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

LastName+FirstName in a single column sorting and filtering

2 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Massimiliano
Top achievements
Rank 1
Massimiliano asked on 10 Jul 2013, 02:29 PM
I think is quite a common scenario, so I was wondering if is there a "simple" way to do the sorting and filtering (with NeedDataSource).
Displaying both in a template column is quite straightforward just Trim(Item.LastName & " " & item.FirstName)
Filtering in SQL Server should be something like "WHERE Trim(LastName+' '+FirstName) LIKE... (filter options)"
Sorting of course should be " ORDER BY LastName ASC,FirstName ASC " and " ORDER BY LastName Desc, FirstName Desc"

Any hint?

2 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 15 Jul 2013, 02:32 PM
Hello Massimiliano,

RadGrid is a bound control and being such it does all it's operations like filtering and sorting on a data level. This means that you can apply a sort or filter expression for a certain field. In the particulars case we have two fields LastName and FirstName and we can sort/filter by them. But RadGrid can not sort/filter by their concatenated value because it is not included in the grid's data source. That said you can resolve the problem by including a filed which represents the concatenated string value in the data source. This will allow you to manipulate the data by using the built-in mechanism of the grid.

Regards,
Angel Petrov
Telerik
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 the blog feed now.
0
Massimiliano
Top achievements
Rank 1
answered on 15 Jul 2013, 03:12 PM
Thank you Angel, I came up with this same idea, usinga view in the db and providing a concatenated field. 
I have yet to try the "editing/inserting" part where the view won't be useful for an automatic implementation, but I guess this can easily overcome. Also "auto" implementation is very rare to find its place in a complex scenario ;)
Tags
Grid
Asked by
Massimiliano
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Massimiliano
Top achievements
Rank 1
Share this question
or