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

grid sort buttons always visible

7 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan Bartsch
Top achievements
Rank 1
Ryan Bartsch asked on 17 Mar 2010, 04:58 AM
Hello,

The standard 'look and feel' for sortable grids at the organsiation at which I work, it to have the sort buttons always visible (even if that column is not sorted). When a column is sorted the appropriate image (i.e. asc or desc image) source would change to an active version.

I'm not here to argue whether or not its a good idea to to always display the sort buttons on every column. I am asking what would be the recommended approach to do what I am attempting.

Many thanks,
Ryan.

7 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 22 Mar 2010, 12:13 PM
Hello Ryan,

One possible option to achieve the desired functionality, would be to get a reference to the header item, for example in the PreRender event handler, and then access the required cell(s):

http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

to add an image, indicating that the column can be sorted, but that no sorting is applied to is. Give this approach a try and let me know how it goes.

All the best,
Yavor
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
James Moyon
Top achievements
Rank 1
answered on 23 Mar 2010, 04:06 AM
Could you please elaborate on how to display the additional image with the appropriate sort action?
Also, is there a way to track whether a column of a grid is currently sorted and in which order (ascending or descending)?

Thanks in advance.
0
Yavor
Telerik team
answered on 24 Mar 2010, 01:57 PM
Hello James,

Attached to this message, is a small sample, which handles a functionality close to the one which you described.
I hope it gets you started properly.

Greetings,
Yavor
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
James Moyon
Top achievements
Rank 1
answered on 25 Mar 2010, 04:48 AM
Thank you very much for your code sample. It was very useful! I have been able to programmatically add sort buttons to the appropriate column headers.

I found out earlier that if I added my own buttons to the PagerTemplate area, with a command name of "Page" and a command argument of "Next" or "Prev", the buttons would automatically assume the appropriate paging behaviour. Is there a way to do so for my sort buttons?

Thanks in advance.
0
Yavor
Telerik team
answered on 30 Mar 2010, 07:45 AM
Hello James,

You can also have a similar setup with the sorting functionality. This is demonstrated in the code sample below:

<telerik:GridTemplateColumn UniqueName="Template1">
<ItemTemplate>
<asp:Label runat="server" ID="Label1" Text='<%#Eval("CustomerID") %>'>
</asp:Label>
</ItemTemplate>
<HeaderTemplate>
<asp:Button runat="server" ID="Button2" Text="Sort" CommandName="Sort" CommandArgument="CustomerID" />
</HeaderTemplate>
</telerik:GridTemplateColumn>

I hope this helps.

Best wishes,
Yavor
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
James Moyon
Top achievements
Rank 1
answered on 12 Apr 2010, 05:11 AM

Although your code is useful, it only toggles between ascending sort / descending sort / no sort.

 

I need to have two buttons, one for each sort direction. Is there a way to specify the sort direction when these buttons are pressed?

Thanks in advance.

0
Yavor
Telerik team
answered on 13 Apr 2010, 01:07 PM
Hi James,

This cannot be handled in such a manner. The sorting command takes as argument the name of the column, and internally determines the sort order. In this case, you can attach to the ItemCommand, and set custom command names for the buttons. According to the name, you can sort ascending and descending, with two different buttons, as per your requirements.
I hope this is a feasible approach for you.

Sincerely yours,
Yavor
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.
Tags
Grid
Asked by
Ryan Bartsch
Top achievements
Rank 1
Answers by
Yavor
Telerik team
James Moyon
Top achievements
Rank 1
Share this question
or