This is a migrated thread and some comments may be shown as answers.

Client-side sorting

4 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zoe
Top achievements
Rank 2
Zoe asked on 13 Nov 2008, 05:12 PM
Hi,

I've come across a few issues when using client-side sorting. I'm managing to work around them all, but just wanted to highlight them, as it would have been ideal if it "just worked like it does server-side" (although perhaps wishful thinking!). I'm working with a grid that has already been in use using server-side binding/sorting, and the query behind the datasource is not 'simple', so for lots of the columns we were using the SortExpression property of columns in markup to get around the fact that it wasn't correct to sort by simply the bound field.
Examples:
-Datafield "ID"; SortExpression "Table.ID" (because of many joins in the actual query)
-DataField "NTextField"; SortExpression "cast(NTextField as nvarchar(3999))" (can't order by an ntext field)
-DataField "Sum"; SortExpression "isnull(number1,0) + isnull(number2,0)"

The issues I've noticed are:
1. The client-side javascript for sorting seems to assume the first space in a sort expression follows a single fieldname to sort on, and that directly afterwards you get the direction if one is present. This isn't the case with some of our sort expressions.
2. It assumes that the fieldname (or maybe it's the columnname) is the same as the first part of the expression up to the space (similar to point 1) which means that when it looks for the sorting buttons it doesn't find them correctly. So using my first example the button might have an id of "gridID__ID__sortAsc" but the sorting functionality looks for "gridID__Table.ID__sortAsc".
3. If there are single quotes in the sort expression (used by sql to indicate strings) then you get javascript errors when the grid first loads, and clicking on the header to sort will cause a postback as it doesn't then call the oncommand event which would normally cancel it in my scenario. Escaping the single quotes (\') did fix the load errors, but then the sortexpression that gets passed to the select is wrong.
4. AllowNaturalSort setting server-side does not carry over to client-side and there doesn't appear to be an equivalent available to set.
5. '+' seems to get removed from the expression altogether (e.g. you might have a field returned that is the sum of 2 underlying numbers).

It would also perhaps be nice to have an OnSort event available?

I've worked around these by removing all our sort expressions from the grid markup and then in the select method swapping out the datafields for the desired sort expression, and hooking into the client-side oncommand event as follows to mimic allownaturalsorting (using telerik RadGridScripts.js as a basis):

    switch (args.get_commandName()) { 
        case 'Sort'// this is to replicate 'allownaturalsorting=false' 
            if (sender.get_masterTableView().get_sortExpressions().toString() == '' && args.get_commandArgument() != '') { 
                var exp = new Telerik.Web.UI.GridSortExpression(); 
                exp.set_sortOrder(Telerik.Web.UI.GridSortOrder.Ascending); 
                exp.set_fieldName(args.get_commandArgument()); 
                var id1 = String.format("{0}__{1}__SortAsc", sender.get_masterTableView().get_id(), args.get_commandArgument()); 
                var id2 = String.format("{0}__{1}__SortDesc", sender.get_masterTableView().get_id(), args.get_commandArgument()); 
                if ($get(id1)) { $get(id1).style.display = ""; } 
                if ($get(id2)) { $get(id2).style.display = "none"; } 
                sender.get_masterTableView().get_sortExpressions().add(exp); 
            } 
            break
    } 
    bindSearchData(sender); 

Of course, I may just be using it in an unexpected way.

Kind regards,

Zoƫ

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 18 Nov 2008, 02:32 PM
Hello Zoe,

Currently RadGrid will not persist any sort expression set server-side when to client-side if you are using client data binding.
If you need to have some sort expressions initially set and bind RadGrid on client you should add those expression before binding the control - as in the code snippet from your post.

Our developers are working on improving RadGrid functionality and more features will be presented in the next releases.

Regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sameer Alibhai
Top achievements
Rank 1
answered on 19 Feb 2010, 08:47 PM
[quote]
4. AllowNaturalSort setting server-side does not carry over to client-side and there doesn't appear to be an equivalent available to set.
[/quote]

Nikolay, can you confirm that this issue has been fixed and in which version? I am using 2009.2.701.20 and setting AllowNaturalSort in the MasterTableView to false does not have any effec and it still allows the NoSort type



0
Nikolay Rusev
Telerik team
answered on 22 Feb 2010, 12:52 PM
Hello Sameer,

AllowNaturalSort is available since Q3 2009 BETA of RadControls for ASP.NET. You can find it in the release notes of RadGrid:
http://www.telerik.com/products/aspnet-ajax/whats-new/release-history/q3-2009-beta-vesion-2009-3-1016.aspx

However there are few fixes since then.

All the best,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sameer Alibhai
Top achievements
Rank 1
answered on 22 Feb 2010, 10:19 PM
Thank you Nikolay

Tags
Grid
Asked by
Zoe
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
Sameer Alibhai
Top achievements
Rank 1
Share this question
or