Sorting in Grouped Column - Telerik Mvc Grid

7 posts, 0 answers
  1. VP
    VP avatar
    21 posts
    Member since:
    Oct 2014

    Posted 13 Nov 2014 Link to this post

    I am trying to add sorting inside grouped columns, So the Grid is grouped by X and Y columns and then I need to sort for the rows in it.
    I need to sort by CustomSortIntegerValue if CustomSort = true, and Alphabetically by Name if CustomSort = false. The last line does not work. Can you please give an pointers/examples on how to achieve this.

    @(Html.Telerik().Grid(Model)
        .Name("Grid")
        .NoRecordsTemplate("Loading ..... Please Wait")
        .Columns(c =>
        {
            c.Bound(x => x.Name).Title("Name");
            c.Bound(x => x.CustomSortIntegerValue).Title("Custom Sort"); 
            c.Bound(x => x.Id).ClientTemplate(Html.ActionLink("Edit", "Edit", new { id = "<#=Id#>" }).ToString()).Filterable(false).Sortable(false).Title("").Width(50);
        })       
              .DataKeys(keys =>
              {
                  keys.Add(x => x.Id);
              })

        .DataBinding(dataBinding => dataBinding.Ajax()
            .OperationMode(GridOperationMode.Client)
                          .Select("RetrieveAllData_AjaxBinding", "CDController"))
        .Groupable(grouping => grouping.Groups(groups =>
                 {
                     groups.Add(x => x.X);
                     groups.Add(x => x.Y);
                 }).Visible(false))
              //.Sortable(sort => sort.OrderBy(sortOrder => sortOrder.Add(x => x.CustomSort ? "CustomSortIntegerValue" : "Name").Ascending()).Enabled(false))
        )
  2. VP
    VP avatar
    21 posts
    Member since:
    Oct 2014

    Posted 17 Nov 2014 Link to this post

    Hello,

    Just checking back for my Question that I posted earlier. Is this even possible?

    Thanks.
  3. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 17 Nov 2014 Link to this post

    Hello,

    You can conditionally add initial sort expressions based on external value using similar to the following approach:

    .Sort(s => {
        if (ViewBag.CustomSort)
        {
            s.Add(c => c.CustomSortIntegerValue);
        }
        else
        {
            s.Add(c => c.Name);
        }
    })

    Also note that Telerik ASP.NET MVC extensions are discontinued and we do not provide support for this product. You should consider migrating to UI for ASP.NET MVC.

    Regards,
    Rosen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  4. VP
    VP avatar
    21 posts
    Member since:
    Oct 2014

    Posted 17 Nov 2014 Link to this post

    Thanks Rosen for your response.

    In my case, it does not even support the Add method you have mentioned (s.Add). Our other projects use Kendo, but this uses Telerik, so would appreciate if you can help me on how can I add sorting on this Telerik Grid (as Pasted in my first post).

    Thanks.
  5. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 18 Nov 2014 Link to this post

    Hi,

    Here is the same snippet with the API for Telerik Extensions for ASP.NET MVC:

    .Sortable(sortable =>
        sortable.OrderBy(s => {
            if (ViewBag.CustomSort)
            {
                s.Add(c => c.CustomSortIntegerValue);
            }
            else
            {
                s.Add(c => c.Name);
            }
        })
    )


    Regards,
    Rosen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. VP
    VP avatar
    21 posts
    Member since:
    Oct 2014

    Posted 19 Nov 2014 in reply to Rosen Link to this post

    Hi Rosen

    The Sorting that you have mentioned is on the complete grid level. If you see my first post, that specifically says, sorting inside a group. So if you see the attached redacted image, in Group - ContentTypeName, the model has IsCustomSort for each ContentTypeName Value - so if IsCustomSort = true then sort by CustomSortIntegerVal - integer value) and if IsCustomSort = false then sort by Name (Alphabetically).

    In the image, red circle is the place where it needs to sort by using the CustomSort, and in the blue circles it needs to sort Alphabetically. Please let me know if you have Questions.

    Thanks.
     
  7. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 19 Nov 2014 Link to this post

    Hi,

    I'm afraid this is not possible. Column sorting can be set for the whole Grid.

    Regards,
    Rosen
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top