We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Want Sort icon in Column Header

hi
i have a griddatabound Grid in which i have a column as "expiry date" and the datain it is of string type , so when we sort it , it does'nt sort according to datetime b'cas its string. so for that i have write my own code on CellClick is that if colindex is that one then sort the datatable and bind it to grid. thats solve my problem , but the issue is that i also want sort icon when user click on the column , so please suggest me solution according to thsi Grid (gridDataBound Grid) . and one more thing is that when i set the datasource of sorted datatable to grid , that time the scroll bar of the grid again moves to start point , that's i not want .
so please look in this issuee and solve my problem.

i'll also attached the code with it

Thanks
Gourav

gridsort.zip

3 Replies

HA haneefm Syncfusion Team July 31, 2007 03:44 PM UTC

Hi Gourav,

The GridDataBoundGrid really does not do any sorting. It delegates the sorting to the IBindingList datasource. So, if you are using a DataTable as the grid''s datasource, it is the dataTable.DefaultView that is doing the sorting. So, if you are seeing the dates being sorted like strings, it suggests that the type of this DataColumn in the DataTable is a string object and not a DateTime object. If this is the case, the simplest way to handle the problem would be to store the value as a DataTime and set GridBoundColumn.StyleInfo.Format to tell the grid to display the DateTime value with a particular format.

If this is not possible, then you would have to do some work to work around the string type being set in the datasource. Here is a forum thread that discusses a couple of ways to do this and has sample information. But changing the DataColumn type will be the simplest solution.

http://www.syncfusion.com/support/forums/message.aspx?&MessageID=21940

Best regards,
Haneef


GN Gourav Nayyar August 1, 2007 06:18 AM UTC

Hi Haneef
Thanks for solution , but my problem is not that you understand. my problem is " i have done sorting manually in my grid by my own code , but now i want to show sort icon on the grid when i click on grid "
so pl'z send me code regarding that.

Thanks
Gourav

>Hi Gourav,

The GridDataBoundGrid really does not do any sorting. It delegates the sorting to the IBindingList datasource. So, if you are using a DataTable as the grid's datasource, it is the dataTable.DefaultView that is doing the sorting. So, if you are seeing the dates being sorted like strings, it suggests that the type of this DataColumn in the DataTable is a string object and not a DateTime object. If this is the case, the simplest way to handle the problem would be to store the value as a DataTime and set GridBoundColumn.StyleInfo.Format to tell the grid to display the DateTime value with a particular format.

If this is not possible, then you would have to do some work to work around the string type being set in the datasource. Here is a forum thread that discusses a couple of ways to do this and has sample information. But changing the DataColumn type will be the simplest solution.

http://www.syncfusion.com/support/forums/message.aspx?&MessageID=21940

Best regards,
Haneef


HA haneefm Syncfusion Team August 1, 2007 06:10 PM UTC

Hi Gourav,

You can handle the QueryCellInfo event of the grid and set the e.Style.Tag property of the column header to your sort direction. Below is a code snippet

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.ColIndex == 7 && e.RowIndex == 0)
{
e.Style.Tag = sortDirection;
// for ascending ListSortDirection.Ascending;
// e.Style.Tag = ListSortDirection.Ascending;
}
}


Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon