iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
See this thread for code example:
http://www.intersoftpt.com/Community/WebGrid/WebGrid-How-to-access-Session-object-in-InitializeRow-event-handler/
There's a sorting problem. When sorting by this Name field, it will get sorted by the value in the DataTable from InitializeDataSource, field List_Name. But in InitializeRow I set the ListName.Text (e.Row.Cells.GetNamedItem("xx").Text) to the value that will be displayed. In the case of this example I prepend just "-DIR-" for folders and "-FIL-" for leaf-nodes. When sorting, it won't get sorted by the displayed text, but by the underlying data field (before updating). For this example, the root-level entry "-FIL-a-" comes before "-DIR-b-", just because "a" comes before "b", but the final text is ignored ("-D.." would come before "-F..").
How can I make sure the list gets sorted by the displayed text? Would I have to implement CustomSort event? How?
Hi Bernard,
I looked at your changes and can see that you just changed the data given to the WebGrid in InitializeRow. That's kind of cheating. Normally, there would be a database call instead of this hardcoded stuff. Of course we could add this logic into the database, but these text modifications are just for displaying, so I don't think this belongs logically into the database and I don't want to do that.
I also tried to change ListName.Value in the InitializeRow event handler in the same way as ListName.Text, but it had no effect. Probably that value is read-only there or something.
So from what I see now, the only way to solve this would be that after the database call in InitializeDataSource I copy the returned resultset into a DataTable and add a column, loop through all rows and set the display value there instead of in InitializeRow event handler. Then I could remove the code in InitializeRow. That way the underlying .Value has the correct values for sorting. I could also set the SortColumn property, but I would still need to create the data column. I don't like to loop through DataSets, but this seems to be the only solution for now.
Yes, having a property to sort by the displayed text instead of the underlying value would be a good idea. Please suggest such a feature request. An even better way (or additional feature) would be some way to modify the underlying data value (and/or the sort value) within the InitializeRow event handler.
Thanks
Hi Eric,
I think the best way to do your scenario is by using DataTable that you mentioned above. In InitializeRow event we can set the value of the cells (it's not read only I think) but it seems the row has been sorted in InitializeRow. It's more elegant if we have feature for sorting by text instead of value. I'll make this feature request and I'll contact you if I heard any feedback from our developer. Thank you for your feedback.
Regards,
Bernard
Hi Bernard
Thanks. As a final comment, if there will be maybe a feature to sort by displayed text, this means that the sorting must be done after the InitializeRow events, because the texts get changed in InitializeRow. So it would be good if the sorting-relevant data could be changed in that event too. Consider a list of calculated date values, that should be sorted by time and not alphabetically. So only the option to switch to text-sorting might not be sufficient for that case. So the best way to add such a feature would be to allow changing the underlying data value (or a special sorting-relevant data value) in InitializeRow event.
For our project this is now not very important anymore, as we have to implement the workaround anyway. But having such a feature would still be good. Please ping to this thread in case there's any update.
This problematic behaviour has already added as feature request #1255. I'll let you know if I heard any news regarding this issue.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname