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

Sorting in Grouped Column - Telerik Mvc Grid

6 Answers 220 Views
Grid
This is a migrated thread and some comments may be shown as answers.
VP
Top achievements
Rank 1
VP asked on 13 Nov 2014, 08:48 PM
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))
    )

6 Answers, 1 is accepted

Sort by
0
VP
Top achievements
Rank 1
answered on 17 Nov 2014, 02:23 PM
Hello,

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

Thanks.
0
Rosen
Telerik team
answered on 17 Nov 2014, 03:52 PM
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.

 
0
VP
Top achievements
Rank 1
answered on 17 Nov 2014, 04:43 PM
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.
0
Rosen
Telerik team
answered on 18 Nov 2014, 07:34 AM
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.

 
0
VP
Top achievements
Rank 1
answered on 19 Nov 2014, 04:21 PM
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.
 
0
Rosen
Telerik team
answered on 19 Nov 2014, 04:42 PM
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.

 
Tags
Grid
Asked by
VP
Top achievements
Rank 1
Answers by
VP
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or