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

[Solved] Sort on a template column?

4 Answers 116 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.
William Brown
Top achievements
Rank 1
William Brown asked on 09 Sep 2010, 10:21 PM
I have checkbox column in a grid and want the uses to be able to sort if it's checked or not.  Is there a way to use a gridbuilder type on the grid to be able to allow sorting on that column?

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 09 Sep 2010, 10:29 PM
Hello William Brown,

 I will suggest you examine this online demo, which shows how to sort column with boolean type.

All the best,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
William Brown
Top achievements
Rank 1
answered on 09 Sep 2010, 10:42 PM

But can you sort on a template colum?

 

our column is a template column that toggles and saves the value.  This removes the sort on that column.  Can you sort on a template column like this?  I couldn't see how in the link you suggest I look at. thanks Georgi

 

columns.Template(o => {
               %>
                   <input type="checkbox" id="IsLockedOut" name="IsLockedOut" 
                   <% if (o.IsLockedOut) { %>
                       checked="checked"
                   <%} %>
                    onclick="OnLockedOutToggle('<%= o.UserName %>')" />
               <%
               })
               .Width(30)
               .Title("IsLockedOut"
               .HtmlAttributes(new { align="center" });

0
Accepted
Georgi Krustev
Telerik team
answered on 10 Sep 2010, 09:22 AM
Hello William Brown,

In the way how the column is declared, grid does not know on which property to sort. In order to achieve your goal you need to add Bound column with server template:
columns.Bound(o => o.IsLockedOut)
       .Template(x => {
               %>
                   <input type="checkbox" id="IsLockedOut" name="IsLockedOut"
                   <% if (o.IsLockedOut) { %>
                       checked="checked"
                   <%} %>
                    onclick="OnLockedOutToggle('<%= o.UserName %>')" />
               <%
               })
               .Width(30)
               .Title("IsLockedOut")
               .HtmlAttributes(new { align="center" });


All the best,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
William Brown
Top achievements
Rank 1
answered on 10 Sep 2010, 05:09 PM
Thanks Georgi!

Works perfectly. I had to change o. to x. under the template if statements, but it is what we were looking for.

Bill
Tags
Grid
Asked by
William Brown
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
William Brown
Top achievements
Rank 1
Share this question
or