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

[Solved] Problem sorting grid with HeaderTemplate

2 Answers 202 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mario
Top achievements
Rank 1
Mario asked on 06 Sep 2011, 03:21 PM
Hi guys!
I've a problem with the Grid component; I'm trying to sort columns with HeaderTemplate but it didn't works
The columns with the Title property works fine, but the columns with the HeaderTemplate didn't works.
Here my code
Html.Telerik().Grid(Model.listValori)
           .Name("Articles")
           .Columns(columns =>
               {
                   columns.Bound(e => e.IDArticle).Template(e => {Response.Write(e.IDArticle); })
                               .Title(
"Id Article");
              columns.Bound(e => e.isVisible).Template(e => {Response.Write(e.isVisible);})                                            
                       .HeaderTemplate("<img src='/img/myimg.gif'  />")
                       .Width(40);
                                    columns.Bound(e => e.Description).Template(e =>{ Response.Write(e.Description);})                      
                       .Title("Description")
                       .Width(40);
               })                        
               .Scrollable(200)
               .Sortable()
               .Footer(false)             
               .HtmlAttributes(new { @class = "TelerikGridArticle" })
           .Render();

I can sort the first and the third column but not the second.
Is there a workaround to sort a column with HeaderTemplate filled?

Thank You!

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 06 Sep 2011, 04:01 PM
Hello Mario,

The header template should contain a clickable element, which triggers sorting by means of a custom Javascript function. Please use the Grid client API:

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-client-api-and-events.html#sort

Regards,
Dimo
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
David
Top achievements
Rank 1
answered on 08 Mar 2013, 03:01 PM
Hello Dimo,

I have attempted to use the code detailed in your link. Using the code:

var grid = $("#Grid").data("tGrid");

I am able to manipulate the grid just fine. eg, hide columns, show columns. etc. But for some reason the line: 

grid.sort("OrderID-desc");

is not sorting the grid. Can you suggest some possible reasons?

Thank you,
David Fliss
Tags
Grid
Asked by
Mario
Top achievements
Rank 1
Answers by
Dimo
Telerik team
David
Top achievements
Rank 1
Share this question
or