Previous or Next Item in List
Application Type
Traditional Web

Hi All ,

I want to apply a CSS class in the extended properties in a List Widget. Use case is : If the the value of one field in current row matches the value of that field in the next row of that List , then the class should get added to that row. 

I want something like this :

public static bool IsNextRecordAgencyTied(DataTable dt, int nextCounter, string agencySeed)
{
bool bAgencyTied = false;
try
{
if (nextCounter <= dt.Rows.Count)
{
// Check if the next record has the same agency record and if not set the bSameSetOfMultiples accordingly
if (!String.IsNullOrEmpty(dt.Rows[nextCounter]["Agency_Seed"].ToString()))
{
string nextAgencySeed = dt.Rows[nextCounter]["Agency_Seed"].ToString();
if (agencySeed == nextAgencySeed)
bAgencyTied = true;
}
}
}
catch (Exception ex)
{  

}
return bAgencyTied;
}


I have tried with the available list actions but can't figure out how to compare with the current row and next row.

Solution

Hello Arpit Arora,

You can do this. Create a function that will get the id of the current record, and the function will check the previous record on the list, if the value is equal you return true if not false. Be careful doing the condition if you are in the first record.

Then on the extent properties, you call the function. And you do this condition

if(functionX(record.id),"class","")

That's one option or you can create a structure that you will include on that structure a boolean attribute like isEqual and in a data action you loop the list and you will fill that attribute depending if is equal to the next record or not and of course, you append the entity structure data too. :)

Let me know if it helps.

Kind Regards,

Márcio

Hi Marico, 

I would like to understand one thing , if you can help. On the extended properties, if we use style or class , what is the difference between them . I mean to say which one is the recommended way to go. Using style attribute impacts the performance as inline style has been added , is it the case ? How this style/class is computed on the runtime. Just asked if you can share. Thank you.

Of course, don't use style, the style will add inline styles. But a class is something you will add to the element but you still have control over that on the theme!

So, always use class if you can. There are some cases where you need to use styles if you have multiple use cases and you can cover everything, but it's rare to happen.

Thank you! :)

Hi Arpit 

If I understand your use case correctly you can do as in the image below ;) 

Best Regards,

Rúben

Hi Ruben ,

This is even a simplified solution than mine. Thanks for sharing this.

Solution

Hi Everyone,

First of all, thank you to all for providing your valuable suggestions. Before going through your answers , I did some experiments on the solution and managed to implement it . I will just write it through for any future references. 

Added an extra attribute of boolean type (IsAgencyTied) to the structure of the list. Set the default value of this attribute to false.

Did a loop through over the list and in each iteration :

1.  Checked whether the current row number is greater than zero.

2. Added two local variables, CurrentRowIndex and PreviousRowIndex assigned the value List.CurrentRowNumber and List.CurrentRowNumber-1 . 

3. Used another two local variables CurrentRecordAgency and PreviousRecordAgency and assigned the value List[CurrentRowIndex].Agency and List[PreviousRowIndex].Agency.

4. Finally compared whether CurrentRecordAgency is equal to PreviousRecordAgency and if so, set the List.IsAgencyTied to true.


The suggestions you provided quite similar to my solution , hence thank you once again.

Hi Arpit,

To get the Previous or Next Item from List, You can use Index instead of current in List widget. 

DataPointList[1].Color

Thanks

Vinod

Hi Vinod , This will give us an item of an specified index. Don't think this will help my use case as I need to loop through the list accessing current and [current+1] item.

Hi Arpit,

You can get List total items in Count Property. You can loop your list based on count. Create a client function to check Previous or Next Item.  Please see the below screen - We created this as a function so you can call it on your screens aggregates or you can apply your CSS based on this function output parameter.



Solution

Hello Arpit Arora,

You can do this. Create a function that will get the id of the current record, and the function will check the previous record on the list, if the value is equal you return true if not false. Be careful doing the condition if you are in the first record.

Then on the extent properties, you call the function. And you do this condition

if(functionX(record.id),"class","")

That's one option or you can create a structure that you will include on that structure a boolean attribute like isEqual and in a data action you loop the list and you will fill that attribute depending if is equal to the next record or not and of course, you append the entity structure data too. :)

Let me know if it helps.

Kind Regards,

Márcio

Hi Marico, 

I would like to understand one thing , if you can help. On the extended properties, if we use style or class , what is the difference between them . I mean to say which one is the recommended way to go. Using style attribute impacts the performance as inline style has been added , is it the case ? How this style/class is computed on the runtime. Just asked if you can share. Thank you.

Of course, don't use style, the style will add inline styles. But a class is something you will add to the element but you still have control over that on the theme!

So, always use class if you can. There are some cases where you need to use styles if you have multiple use cases and you can cover everything, but it's rare to happen.

Thank you! :)

Hi Arpit 

If I understand your use case correctly you can do as in the image below ;) 

Best Regards,

Rúben

Hi Ruben ,

This is even a simplified solution than mine. Thanks for sharing this.

Solution

Hi Everyone,

First of all, thank you to all for providing your valuable suggestions. Before going through your answers , I did some experiments on the solution and managed to implement it . I will just write it through for any future references. 

Added an extra attribute of boolean type (IsAgencyTied) to the structure of the list. Set the default value of this attribute to false.

Did a loop through over the list and in each iteration :

1.  Checked whether the current row number is greater than zero.

2. Added two local variables, CurrentRowIndex and PreviousRowIndex assigned the value List.CurrentRowNumber and List.CurrentRowNumber-1 . 

3. Used another two local variables CurrentRecordAgency and PreviousRecordAgency and assigned the value List[CurrentRowIndex].Agency and List[PreviousRowIndex].Agency.

4. Finally compared whether CurrentRecordAgency is equal to PreviousRecordAgency and if so, set the List.IsAgencyTied to true.


The suggestions you provided quite similar to my solution , hence thank you once again.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.