Posted 11 April 2024, 9:58 pm EST
- Updated 11 April 2024, 10:03 pm EST
Hello,
To apply sorting on any FlexGridColumn by default you can specify the ‘sortDescriptions’ property of the flexGrid’s collectionView. In case, if you are not aware of the CollectionView, the CollectionView acts as a data source for the Wijmo FlexGrid, and all the paging, sorting, and grouping actions are handled at the CollectionView level. You’ll need to create a new CollectionView and assign it to the ‘itemsSource’ property of the FlexGrid. Whenever, a simple array is assigned to the ‘itemsSource’ property of the FlexGrid, a CollectionView is created internally, which then acts as the data source. Please refer to the following code snippet that shows, how you can create a CollectionView with default sorting applied on a Column -
let view = new CollectionView(data, {
// sort the data by date in descending order
sortDescriptions: [
new SortDescription('date', false),
]
})
And to apply some default filtering on the FlexGrid, you can set the ‘filterDefinition’ property of the FlexGridFilter, like this -
let filter = new FlexGridFilter(theGrid, {
filterDefinition: '{"defaultFilterType":3,"filters": [{"binding":"country","type":"value","uniqueValues":null,
"sortValues":true,"maxValues":250,"exclusiveValueSearch":true,
"showValues":{"Germany":true}}]}'
})
Please refer to the following sample demonstrating the same - https://jscodemine.mescius.io/share/S11LgJy8MU2KQTubDUQ5Yg/
To get the filterDefinition as per your needs, you can first apply the filter on the FlexGrid and then check the ‘filterDefinition’ property of the grid filter, which will return the filterDefinition of the currently applied filter in string format. You can set the same definition initially to apply default filtering on the grid. Please refer to the attached screenshot for the same -
Here are some API links for your reference - https://developer.mescius.com/wijmo/api/classes/Wijmo.Sortdescription.html
https://developer.mescius.com/wijmo/api/classes/Wijmo.Collectionview.html
https://developer.mescius.com/wijmo/api/classes/Wijmo_Grid.Flexgrid.html
https://developer.mescius.com/wijmo/api/classes/Wijmo_Grid_Filter.Flexgridfilter.html
In case, you face any issues, please let us know.
Regards