Client-side sorting

5 posts, 0 answers
  1. Zoe
    Zoe avatar
    6 posts
    Member since:
    Aug 2007

    Posted 13 Nov 2008 Link to this post

    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ë

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 18 Nov 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sameer Alibhai
    Sameer Alibhai avatar
    4 posts
    Member since:
    Apr 2009

    Posted 19 Feb 2010 Link to this post


    4. AllowNaturalSort setting server-side does not carry over to client-side and there doesn't appear to be an equivalent available to set.


    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



  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 22 Feb 2010 Link to this post

    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.
  6. Sameer Alibhai
    Sameer Alibhai avatar
    4 posts
    Member since:
    Apr 2009

    Posted 22 Feb 2010 Link to this post

    Thank you Nikolay

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017