ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Grid Datatype column
Title:
B
I
{code}
?
Hi, I have a grid with a column. The data in the column is string. However I want to treat it as an int. When sorting now it is text sorted rather then int sorted. I have tried in the map to map the column to a converted in like this: return Json(new GridModelBuilder<MyObject>(items, g) { Key = "Id", Map = o => new { o.Id, CustomerID = Convert.ToInt32(o.CustomerID), But that resulted still in text sorting (e.g. 213 comes after 1000). Is there a way that the grid treats the value as a number and thus resulting in a number sort order, without having to update the model.
Save Changes
Cancel
mounhim
asked at 21 Jan 2014
the Map is used to modify the display model, but querying is still done using the <T> model in your case MyObject (you should read more on how the grid works here: http://aspnetawesome.com/learn/mvc/Grid), think the easiest solution would be to use a different Model where CustomerId is int
at 21 Jan 2014
Omu
Unfortunately I cant change the model. Also I still like it with string where I can use Contains in the search and use partial of the ID to find a customer. I have read about a solution where one can use a custom comparer. But as far as I can see the whole order by is hidden from me and therefore a custom comparer cannot be implemented. Is there a way to extend the grid by using a custom comparer as is suggested on http://stackoverflow.com/questions/6396378/c-sharp-linq-orderby-numbers-that-are-string-and-you-cannot-convert-them-to-int?
at 22 Jan 2014
mounhim
you can do the ordering yourself, have a look at this page: http://demo.aspnetawesome.com/GridDemo/CustomQuerying
at 22 Jan 2014
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK