LastName+FirstName in a single column sorting and filtering

3 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 10 Jul 2013 Link to this post

    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. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 15 Jul 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Massimiliano
    Massimiliano avatar
    184 posts
    Member since:
    Oct 2012

    Posted 15 Jul 2013 Link to this post

    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 ;)
Back to Top