Posted 14 July 2020, 7:19 am EST
Hi Misel,
The feature itself cannot be added to any grid (FlexGrid, TrueDBGrid, even in MS DataGridView if MS agreed to do such request, etc.) directly when the grid is bound to DataTable, because it requires specific advanced groups sorting based on aggregate values.
In bound mode the grid displays the inner organization of data in datasource - if the datasource supports sorting (e.g. DataTable, or more precisely - corresponding DataView of DataTable) then grid displays sorted data of that datasource.
The DataTable/DataView doesn’t provide any built-in mechanism to implement such sort - there is no method in which we can pass some custom IComparer or Comparison between data rows.
But there are still options to implement such sorting - by creating custom datasource which supports such sorting (but such datasource will be hard to fill from Database using DB adapters) or by creating some columns in DataTable which will have associated aggregate values in it and sorting by that columns firstly.
Such columns can be hidden in the grid control.
So, the key points of the solution:
- Handle mouse click of the column header programmatically in the corresponding event.
- Generate column in datasource which will have corresponding aggregate values and fill that column.
- Sort by that column then sort by grouped columns, then sort by column with sorting value itself.
- Hide associated aggregate columns in the grid.
I’d assume that such sorting (on datasource) can be implemented in any grid - FlexGrid, TrueDBGrid, DataGridView if such a grid have a mechanism to cancel sorting in some corresponding event.
I have attached a sample GroupingDemo_Solution.zip implementing the same, please have a look.
Regards,
Prabhat Sharma.
GroupingDemo_Solution.zip