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

[Solved] Sorting a templated column

5 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chad Johnson
Top achievements
Rank 1
Chad Johnson asked on 21 Dec 2009, 04:21 PM
Greetings,

I'm currently in a bit of a pickle on a project.

I have a grid with the following columns:
DocID (bound column that is a string and display is false),
Type (a templated column that has an image in it),
DisplayName (bound column that is a string),
Owner (bound column that is an int that has display of false),
OwnerName (bound column that is a string),
ModifiedBy (bound column that is an int and has a display of false),
ModifiedByName (templated column with a label within it),
ModifiedDate (bound column with a datetime in it)

I sort on all columns, with exclusion of the ones with display hidden and Type.  The issue I'm having is with ModifiedByDate.  This column is populated with data during OnItemDataBound.  It is loaded based on the ModifiedBy field's value.  To populate it, I go to the database during OnItemDataBound and fill in the label that is within the column.

What I'm curious on is is there a way to sort this column?  Our Data Transfer Object (DTO) doesn't have a place in it for it, plus it's been deemed that it won't ever have one either.  So, my question is, how would I sort this field?  Thank you for any answers.

~Chad Johnson

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 21 Dec 2009, 04:34 PM
Hello Chad,

To enable sorting for a  GridTemplateColumn, you need to set appropriate SortExpression values for those columns and the SortExpression value should match the data field you want to sort on (typically the field a control in the template is bound to).

More information is available in this help topic:
Sorting for GridHyperLinkColumn/GridTemplateColumn

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Chad Johnson
Top achievements
Rank 1
answered on 21 Dec 2009, 04:56 PM
I do understand this, but again, I am binding this column to data during OnItemDataBound and there is no datafield directly connected to it, other than an integer field that I pull the data from.
0
Pavlina
Telerik team
answered on 22 Dec 2009, 02:13 PM
Hi Chad,

I recommend you examine the following articles which elaborate on how to achieve your goal.
Applying custom sort criteria
Programmatic Sorting

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Chad Johnson
Top achievements
Rank 1
answered on 22 Dec 2009, 02:22 PM
Both examples are not particularly helpful.  As I've said before, the column that is being used has no DataField of it's own, hence trying to sort on a DataField of some sort is impossible.  I bind that column with data during OnItemDataBound with data matching the column next to it.  It has no ties to the DataFields, so sorting on one is impossible at the moment, hence why I asked if there was a way to do so without a DataField, and judging by both responses I've received thus far, I would be guessing that is a no since I seem to keep getting the same response each time.

If I had to guess, my best option would be to add the Deleted By column's data that I'm wanting into the DTO I have, or create a temporary DTO/DataTable to store the data for me so that it can be sorted.
0
Pavlina
Telerik team
answered on 23 Dec 2009, 05:18 PM
Hi Chad,

Implementing custom sorting should help you achieve the required functionality. I am not
sure what went wrong on your end.

However, to further trace the issue it will be best if you open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior.
We will debug it locally, and get back to you with additional information.

All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Chad Johnson
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Chad Johnson
Top achievements
Rank 1
Share this question
or