Sort a fields by values of other fields


I wan't to sort these countries by products sold. can we have another sorting button that will sort countries by units sold?
sample data = [{
Sold: 423,
Amount: 3595.5,
Country: 'France',
}, {
Sold: 245,
Amount: 2832.25,
Country: 'Germany',
}
 ]





1 Reply

AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team March 31, 2022 02:52 PM UTC

Hi Dilip,


Currently, there is no options in the member filtering UI to sort filter members based on value field, as per your requirement. However, you can display field members by reordering the given data source based on specified value field in the "load" event. As a result, the value-based sorted members will be displayed in the member filtering UI. Furthermore, to meet this criterion, it is mandatory to set the sort order as "None" in the "sortSettings" property to the specified field. Please refer to the example code below.


Code Example:


 

sortSettings: [{ name: 'Products'order: 'None' }],

 

onLoad(args) {

    args.dataSourceSettings.dataSource.sort((ab=> {

      return a.Sold - b.Sold; //To sort the data based on specific value field in ascending order.

    });

  }

 


Meanwhile, we have prepared a sample for your reference.


Sample: Kwmzdl (forked) - StackBlitz


Also, please refer the following documentation for more details about “sorting” options.


Document: Sorting in React Pivot Table component - Syncfusion


Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.


Loader.
Up arrow icon