We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Sort Observable Listview

Good morning, these days I'm facing an annoying problem. I need to be able to apply a sort on a list composed of Observable. The code I apply is as follows:

 //Ascend
      if (sortAscend) {

         this.filteredVehicles$ = of(vehicleList).pipe(map(result => result.sort((a: any, b: any) => {
            if (a[keyString] < b[keyString]) {
               return -1;
            } else if (a[keyString] > b[keyString]) {
               return 1;
            } else {
               return 0;
            }
         })));

         //Descend
      } else {

         this.filteredVehicles$ = of(vehicleList).pipe(map(result => result.sort((a: any, b: any) => {
            if (a[keyString] > b[keyString]) {
               return -1;
            } else if (a[keyString] < b[keyString]) {
               return 1;
            } else {
               return 0;
            }
         })));
      }

 but this triggers the ExpressionChangedAfterItHasBeenCheckedError error, going to change the data later. Is there a way I can avoid this?

Regards,

Emanuele

3 Replies

SP Sowmiya Padmanaban Syncfusion Team November 15, 2019 12:17 PM UTC

Hi Emanuele, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your attached code snippet. We suspect that, you have tried to perform custom sorting operation for ListView component. But our Listview component, we have provided a support for sorting by using sortOrder property to perform sorting.  
 
For your reference we have prepared a sample. Refer the sample link below. 
 
 
To know about the sorting, refer the below link
 
 
 
 
If you want to perform custom sort operations, can you please share additional details regarding your requirement it will helpful for us to resolve your issue at earlier. 
 
 
Please let us know, if you have any concerns. 
 
 
Regards, 
Sowmiya.P 



EM Emanuele replied to Sowmiya Padmanaban November 15, 2019 01:07 PM UTC

Hi Emanuele, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your attached code snippet. We suspect that, you have tried to perform custom sorting operation for ListView component. But our Listview component, we have provided a support for sorting by using sortOrder property to perform sorting.  
 
For your reference we have prepared a sample. Refer the sample link below. 
 
 
To know about the sorting, refer the below link
 
 
 
 
If you want to perform custom sort operations, can you please share additional details regarding your requirement it will helpful for us to resolve your issue at earlier. 
 
 
Please let us know, if you have any concerns. 
 
 
Regards, 
Sowmiya.P 


Thanks for the reply, it's not a suspect, but I confirm that I created a custom sorting, since I have an observable list of a custom class, having to sort it by foreign key, which could be any data in it.


KR Keerthana Rajendran Syncfusion Team November 18, 2019 11:42 AM UTC

Hi Emanuele,  
 
Good day to you. 
 
Please refer to the solutions provided in the below link for resolving the reported error during sorting.  
 
 
After resolving this error, you can use fields and dataSource property to bind the re-ordered list data to EJ2 ListView component. 
 
Please let us know if any concern on this.  
 
Regards, 
Keerthana.  


Loader.
Live Chat Icon For mobile
Up arrow icon