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))
)
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
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.
Just checking back for my Question that I posted earlier. Is this even possible?
Thanks.
0
Hello,
You can conditionally add initial sort expressions based on external value using similar to the following approach:
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
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.
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
Hi,
Here is the same snippet with the API for Telerik Extensions for ASP.NET MVC:
Regards,
Rosen
Telerik
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.
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
Hi,
I'm afraid this is not possible. Column sorting can be set for the whole Grid.
Regards,
Rosen
Telerik
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.