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

Conditional Sort Expression

2 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 15 May 2012, 04:06 PM
I have a column on a grid that can contain data from one of two fields depending on some condition.  This condition is evaluated on a row by row basis, so one row can have data from one field, and the next field can have data from another field.

The pseudo logic looks like this:

if (record is user created)
field = date created
else
field = date assigned

How should I set the sort expression on this column?

2 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 18 May 2012, 09:17 AM
Hello Dennis,

A column in RadGrid can only be bound to a single data field, so you can sort only by it. From there, it is up to you to decide on the logic for replacing the cells content in the ItemDataBound event.
You might consider having two columns for the two fields and only switch their visibility dependant on some condition.

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Dennis
Top achievements
Rank 1
answered on 18 May 2012, 01:24 PM
That is the conclusion I came too as well - that a single column can only be bound by a single field.

The challenge is not that I have two seperate columns of data - that would be easy.  The challenge is that the data I have a single column that the dat for which can come from one of two source fields, depending on the value of another source field.

I got around it by simply adding another field to the data object and moving the logic to assign the field to my business logic (where it belongs, anyway... :))  I then assign the column to that source field and everything works just fine.

Thank you for your reply.
Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Dennis
Top achievements
Rank 1
Share this question
or