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

Issue with individual column sorting in Telerik MVC grid

1 Answer 256 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rameez
Top achievements
Rank 1
Rameez asked on 12 Jan 2015, 12:52 PM
Hi 

I am using Telerik(Product Version 2012.3.1018.340) MVC grid for my project. When I am setting initial Sort configuration with multiple columns, It have an issue with individual column sorting. The individual column sorting is not at all working in my grid

It is working fine if I didn't set initial sort order (ie, if i give just ".sortable()"). But i want to set initial sort order also individual column sort order functionality

I tried with operation mode is client. Then for one time the sorting is happening only for anyone column which we clicked first. Next time when we try to click on any other column to sort it won't work. 

I used the following code in my project, please help me to tackle this issue

view
------

Html.Telerik().Grid<MyApplication.MainApplication.Models.ApplicationModel.ApplicationViewModel>().Name("Grid1")
            .Columns(col =>
            {
                col.Bound(c => c.UserID).ClientTemplate(
                    "<a href='" + Url.Content("~/Index/Details/") + "<#= UserID #>' title='Details' class='lnkDetails'><#= Number #></a>"
                    ).Title("Number").Filterable(false);
                col.Bound(c => c.FirtName).Filterable(false);
                col.Bound(c => c.LastName).Filterable(false);
                col.Bound(c => c.RID).Hidden();
                col.Bound(c => c.Active).Filterable(false).ClientTemplate(
                    "<input type='checkbox'" + "<#= Active?\"checked\":\"\" #>" + " OnClick='return false' />"
                    ).Width(115);
                col.Bound(c => c.StartDate).Filterable(false).Format("{0:d}").Width(115);
                col.Bound(c => c.CloseDate).Filterable(false).Format("{0:d}").Width(112);
                if (currentUser.AdminRole && (currentUser.DataRole || currentUser.StaffRole))
                {
                    col.Bound(c => c.ID).ClientTemplate(
                            "<a href='" + Url.Content("~/Controller/Create/") + "<#= UserID #>' title='New Contact' class='edit'>New Contact</a>"
                            + "<a href='" + Url.Content("~/Controller/Details/") + "<#= UserID #>' title='Details' class='details action-margin'>Edit</a>"
                            + "<a href='" + Url.Content("~/Controller/Delete/") + "<#= UserID #>' title='Delete' class='delete action-margin'>Delete</a>"
                        ).Title("Action").Filterable(false).Sortable(false).Width(90);
                }
                else if(currentUser.AdminRole)
                {
                    col.Bound(c => c.UserID).ClientTemplate(
                            "<a href='" + Url.Content("~/Controller/Details/") + "<#= UserID #>' title='Details' class='details'>Edit</a>"
                            + "<a href='" + Url.Content("~/Controller/Delete/") + "<#= UserID #>' title='Delete' class='delete action-margin'>Delete</a>"
                        ).Title("Action").Filterable(false).Sortable(false).Width(90);
                }              
                else
                {
                    col.Bound(c => c.UserID).ClientTemplate(
                            "<a href='" + Url.Content("~/Controller/Details/") + "<#= UserID #>' title='Details' class='details action-margin'>Edit</a>"
                        ).Title("Action").Filterable(false).Sortable(false).Width(75);
                }
            })
 
                 .DataBinding(dataBinding => dataBinding.Ajax().Select("_Index", "Controller"))                
                 .Pageable(p => p.PageSize(30))                              
                 .Filterable(f => f.Filters(filters =>
                 {
                     filters.Add(c => c.Number).StartsWith((string)ViewData["Number"]);
                     filters.Add(c => c.FirstName).StartsWith((string)ViewData["FirstName"]);
                     filters.Add(c => c.LastName).StartsWith((string)ViewData["LastName"]);
                 }))
                 .Sortable(sorting => sorting
                        .Enabled(false)
                        .SortMode(GrUserIDSortMode.MultipleColumn)
                        .OrderBy(sortOrder =>
                        {
                            sortOrder.Add(o => o.Number);
                            sortOrder.Add(o => o.FirstName);
                            sortOrder.Add(o => o.LastName);                           
                            sortOrder.Add(o => o.Active);
                            sortOrder.Add(o => o.StartDate).Descending();
                            sortOrder.Add(o => o.CloseDate).Descending();
                            sortOrder.Add(o => o.UserID);
                        }))
                .Render();

controller
----------

[GridAction]
public ActionResult _Index()
{
    return View(new GridModel<UserViewModel>
    {
        Data = GetCases().ToList()
    });
}

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 14 Jan 2015, 08:50 AM

Hello Rameez,

I'm afraid the Telerik Extensions for ASP.NET MVC has been discontinued some time ago (June 2013) in favor of UI for ASP.NET MVC product. Therefore, we do not provide support for this product and I will suggest you to consider upgrading to Kendo UI for ASP.NET MVC.

On a side note to just clarify how the MultipleColumn sorting works. As you may know in MultipleColumn sort mode the sorting with be "stacked up" - first the data will be ordered by the first sort descriptor than on the second one etc. Thus, if the values of the first sort expression field are unique, ordering on other fields will not have any effect as there is only one item in this "sort group". For example, if we have the following items: 

[ { id: 1, name: "name3" }, { id: 2, name: "name2" }, { id: 3, name: "name4" }, { id: 4, name: "name2" } ]

If if sorted first by name and then on id field we will get the following result:

      [ { id: 2, name: "name2" }, { id: 4, name: "name2" }, { id: 1, name: "name3" }, { id: 3, name: "name4" } ]

Note that only within the first sort "group" (name2) the id field is sorted. In the other where there is only single item sorting on the id field will not change the ordering.

Also note that you should have Enabled setting set to true in order sorting to work.

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
Rameez
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or