Hi,
I am facing a problem while sorting on date column when header is clicked. The dates are sorted as string.
The following is the code i am using.
sprData.SetText(SPR_COL_DTM, idx,
).value))
this is the code which populates the column in Ultrawingrid.
Thank you,
Basavaraj P Hiremath.
It would be better to use SortComparer that simply ignores the time portion of the date than to alter the data in this way or return a date as a string.
Ths is happening due to the Date + Time format is bound to the coloumn. To acheive both sorting and filtering sametime you need to get the date portion out before bind it to the grid. I had the same problem and I could achive it using following code in the SQL select statement.
CONVERT(datetime, CONVERT(CHAR(10), OrderDate, 103), 103) as OrderDate
If the values in the column are of type DateTime, then they will be sorted as dates. There is no Date datatype in DotNet as far as I am aware.
It sounds to me like your database is using some unusual type that the DotNet BindingManager or DataTable does not know how to handle and so it's falling back to using strings. That has nothing to do with the grid and the grid has no control over this.
If you need to handle the sorting yourself, you could use a SortComparer on the grid column and compare the values yourself. Perhaps you can use DateTime.Parse to convert the date strings into actual dates.
But you might be better off trying to find out why your date values are being interpreted by DotNet as string, since sorting will not be the only problem this causes. You will have problems filtering, summarizing, and dealing with the dates in a whole lot of ways if they are stored as strings.
The value that is coming from database is of "date" data type. Do i need to convert this to integer type then sort it and then again convert it back to date and then populate the grid...?
You can set: ultraGrid.DisplayLayout.Bands[0].Columns[0].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DateTime;. But it's can't support format {0:MMM d yyyy hh:mm:ss:ffftt}