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

How can I sort a telerik grid template column?

4 Answers 203 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Young
Top achievements
Rank 1
Young asked on 16 Jul 2012, 04:46 PM

Hi, 

I have a telerik grid which contains a template column.

What I would like to do is only apply sorting to this template column and NO other column in the grid.

Please can someone advise me on how I can go about doing this for the Name column? 
Any help would be much appreciated as I am new to using Telerik grids.

Thank you very much

 @(Html.Telerik().Grid(Model.MyGrid)
                 .Name("MyGrid")
                 .Columns(columns =>
                              {
                                  columns.Template(c => @Html.ActionLink(c.Name, "Action", "Controller", new { id = c.Id }, null)).Width(100).Title("Name");
                                  columns.Bound(c => c.Title).Width(100);
                                  columns.Bound(c => c.Occupation).Width(100);
                              })
                 .Sortable(sorting => sorting.Enabled(true)))

4 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 09 Oct 2012, 05:42 PM
I'm having the same issue, has there been any resolution to this?
0
Leon
Top achievements
Rank 1
answered on 18 Oct 2012, 04:32 PM
Yes I am having this issue as well.. is there a way to do this or is it all columns or no columns?
0
Mark
Top achievements
Rank 1
answered on 29 Oct 2012, 02:26 AM
you can try the following:

.Sort(sort => sort.Add(x => x.fieldvalue))

note: fieldvalue is the fieldname that you want to sort. 

Hope it help

Thank you,
0
Brendon
Top achievements
Rank 1
answered on 11 Nov 2012, 08:25 PM
I did not have the same exact issue but I found this helpful:

http://www.telerik.com/community/forums/aspnet-mvc/grid/make-a-grid-sortable-on-column-with-template.aspx

I needed to sort a Template Column. First you must specify a bound column and then attach the template. It will sort by the bound column.

My own code making use of this. It will sort by Company Name.
columns.Bound(e => e.CompanyName).Template(@<text></text>).ClientTemplate("<a href='" + Url.Action("Details", "Customers") + "/#=CustomerId#'>#=CompanyName#</a>").Title("Customer");
Tags
Grid
Asked by
Young
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Leon
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Brendon
Top achievements
Rank 1
Share this question
or