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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sort Observable Listview

Thread ID:

Created:

Updated:

Platform:

Replies:

149101 Nov 14,2019 11:54 AM UTC Nov 18,2019 11:42 AM UTC Angular - EJ 2 3
loading
Tags: ListView
Emanuele
Asked On November 14, 2019 11:54 AM UTC

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

Sowmiya Padmanaban [Syncfusion]
Replied On 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 


Emanuele
Replied On 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.

Keerthana Rajendran [Syncfusion]
Replied On 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.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon