Hi Team,
I am currently using a UltraGrid which bind to UltraDataSource. I want to apply sort function on the grid.
1. I tried grid.SortedColumns.Add(XXX). This applied the sort on Grid. However, I found out this won't effect the data on UltraDataSouce which somehow I need to sorted as well.
2. Then I tried to sort on the ultraDataSource. I sorted the tag of rows as well. However, it doesn't apply any sort on the grid. Am I missing anything? Do I need to sort on the UltraDataSource.Rows rather than Tag? How can I get the businees object behind and sort on the them?
List<Row> rows_= mainUltraDataSource.Rows.Tag as List<Row>;
rows_.Sort(XXX)
Thanks,
Xin
Hi,
The Tag property on the Rows collection is just a place to store extra data. It's not a List of any kind and sorting it will do nothing unless you happen to have placed an object into it that supports sorting. Either way, this will not affect the rows of the UltraDataSource.
The UltraDataSource has no built-in sorting functionality.
Sorting the grid will never affect the order of the rows in the data source. This would not make any sense, since the same data source could be bound to any number of grids.
Perhaps if I knew more about why are you trying to sort the data source, I could point you in the right direction.
Hi Mike,
Thanks for your reply.
The reason why I need to do sort on data srouce level is due to we get data/insert new data all on data source rather than from the real grid.
I do place an object into UltraDataSource.Rows.Tag which supports sorting. Now, after I refresh my grid, I do see the sorting applied. However, it just apply to the first band. It doesn't apply to the child band even if I've already sort the child rows of the parent object Row. Besides, it doesn't change the child band sturcture either. For example, before sorting, the row structur is like below:
Row 1 -> Child Row 1, Child Row2.
Row2
After sorting, it's like below:
Row 2 -> Child Row 1, Child Row2.
Row 1
Could you please advice?
The Sort external choices is working perfectly. However, I still didn't find a way to sort on UltraDataSource.Rows. Just as you mentioned before, change the order or UltraDataSource.Rows.Tag doesn't really change the UltraDataSource.Rows. Do you have any example to achieve this?
Many Thanks,
Hi Xin,
No, there's no support in UltraDataSource for sorting rows.
You could try sorting the rows by removing and then re-inserting the row in the correct place, but I would not recommend this approach, since the grid will get a notification every time a row is removed or added.
What you will probably need to do is change the DataSource of your grid to a data source that has built-in sorting support like a DataTable.
The reason I need to use UltraDataSource is because I need it's Load On Demand function to hlep on performance. I am current using removing and re-inserting the rows as alternertive way. It works fine. However, about your conern about grid will get a notification every time a row is removed or added, Can we use _grd.BeginUpdate() to avoid this?
btw, Is there any reason that ultradDataSource doesn't support sort? It will be great that it supports sort as other data source.
yuxin0717 said:However, about your conern about grid will get a notification every time a row is removed or added, Can we use _grd.BeginUpdate() to avoid this?
Using BeginUpdate/EndUpdate is a good idea.
You can also use SuspendRowSynchronization and RemoveRowSynchronization to improve performance.These should be used inside the BeginUpdate/EndUpdate block.
yuxin0717 said:btw, Is there any reason that ultradDataSource doesn't support sort? It will be great that it supports sort as other data source.
It's never been a big feature request. Probably because the grid already has sorting built-in.
By the way... if you are using UltraDataSource for it's LoadOnDemand functionality, then sorting the data would require loading all of the data into memory, anyway, thus defeating any benefits from loading on demand.
Thanks for your suggestion!
About yout command on LoadOnDemand, that's exactly the reason why I need to sort on data source level, because at the time I sort, I haven't load all data yet. And after I sort, I may need to insert more rows according to my current structure!
I presume ultraDataSource dosen't support group by either? So we somehow need to remove/insert rows?
yuxin0717 said:I presume ultraDataSource dosen't support group by either?
That is correct, it does not support OutlookGroupBy.
yuxin0717 said:So we somehow need to remove/insert rows?
If you are loading on demand, then I think you can simply clear any cached information in the UltraDataSource and tell it to refresh itself from the "real data. So you would sort your data and then call ResetCachedValues on the UltraDataSource which will throw away any accumulated data and re-load as needed.