ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Sorting grid with date
Title:
B
I
{code}
?
I need to show Date string in format "yyyy-MM-dd hh:mm tt" (e.g., 2021-11-27 09:58 AM). I am converting DateTime to Pacific time zone then to string to render in grid and then formatting it. here is the map function property" protected object MapDbViewModelToView(DemoViewModel o) { return new { o.Id, o.DateValue1, o.DateValue2, DateString = o.DateValue.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(o.DateValue.Value, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")).ToString("yyyy-MM-dd hh:mm tt", CultureInfo.CurrentCulture) : TimeZoneInfo.ConvertTimeFromUtc(o.DateValue2, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")).ToString("yyyy-MM-dd hh:mm tt", CultureInfo.CurrentCulture), } } Here is the grid column code View: @(Html.Awe().Grid("DemoGrid") .Columns( new Column { Header = "Audit", ClientFormat= ".(DateString)", Bind = "DateValue", Width = 180, Sortable = true, Sort = Omu.AwesomeMvc.Sort.Desc } )) It is not sorting grid properly when sorting by clicking on date column header, instead it is mixin dates.
Save Changes
Cancel
Sam Mosaic
asked at 27 Nov 2021
the data is being sorted in the Db, based on the `DateValue` column, you are displaying in the grid cell for this column another Column (DateValue2) which doesn't participate in sorting. to check the sorting you need to temporarily use `DateString = o.DateValue.ToString()` and to know how to define your grid columns, first you need to know how your sql query should look like.
at 27 Nov 2021
Omu
Do I need to apply sorting only at one place, either in SQL query or Grid. Right?
at 27 Nov 2021
Sam Mosaic
the query will be generated by EF you just need to decide how you actually want to sort, or how the final sql query should look like, right now it is `... ORDER BY DateValue`
at 27 Nov 2021
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