This is a migrated thread and some comments may be shown as answers.

Sorting String Fields in Radgrid....

3 Answers 382 Views
Grid
This is a migrated thread and some comments may be shown as answers.
raaj
Top achievements
Rank 1
raaj asked on 15 Oct 2010, 04:06 AM
Team,

In one of our application we are binding the dynamically generated datatable (With all Field datatypes are String) to a Radgrid.
Problem is when we apply sorting on those string fields it wont sort numerically, instead of that sorting occurs on string.

My question is without change the datatypes in datatable is it possible to change the columns of Radgrid to numeric before apply sorting..

Pls. help me on this. Client wants it immediately.


Thanks,

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 20 Oct 2010, 10:52 AM
Hi Rajesh,

The way that sort mode is interpreted depends on the DataType of the column:

  • When the DataType is "String", columns are sorted alphabetically.
  • When the DataType is a numeric type such as "Integer" or "Double", columns are sorted numerically.
You can skip this default sort behavior and provide your own custom sort order for a column by setting the AllowCustomSorting property of the corresponding table view. With custom sorting enabled, RadGrid displays the sorting icons but does not actually sort the data. Instead, you perform the custom sorting inside theSortCommand event handler.

You can follow the logic suggested in this forum post for your scenario.

Regards,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Doug
Top achievements
Rank 1
answered on 17 Aug 2011, 05:50 PM
Sorting does not seem to work as simply as just setting the DataType. For example I have two data bound columns in my rad grid:
        ctrlBoundCol = new GridBoundColumn()
        ctrlBoundCol.AllowSorting = True
        ctrlBoundCol.DataType = GetType(System.DateTime)
        ctrlBoundCol.HeaderText = "Date Requested"
and
        Dim ctrlDecimal As New GridNumericColumn()
        ctrlDecimal.ReadOnly = True
        ctrlDecimal.AllowFiltering = True
        ctrlDecimal.AllowSorting = True
        ctrlDecimal.HeaderText = "Total"
        ctrlDecimal.DataField = "Total"
        ctrlDecimal.DataType = GetType(int32)
then bind data to the grid using XML data where the data are attributes (and thus LOOK like strings), for example:
  <row RequestDate="11/17/2010 12:01:05 AM" total="1" Status="Processed" />

These columns thus sort like strings, not like the date or integer. How can I solve this? Must I change my XML to pass the data as elements like so?
 <row><RequestDate>11/17/2010 12:01:05 AM</RequestDate><total>1</total><Status>Processed</Status></row>







0
Tsvetina
Telerik team
answered on 19 Aug 2011, 12:23 PM
Hello Doug,

Are you using an XmlDataSource to bind the grid or you create some custom object to bind the grid to? If it is the first, have in mind that XmlDataSource does not support sorting (MSDN link for reference). If you are binding the grid on the server, the fields inside its datasource should be of the type that you specify inside the column declarations.

Regards,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
raaj
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Doug
Top achievements
Rank 1
Share this question
or