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

Problem with ordering and filtering

8 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ejaz
Top achievements
Rank 1
Ejaz asked on 05 Mar 2015, 06:10 AM
Hi,

I'm facing a problem with ordering and filtering for Gridview control. For some reason '100' is considered smaller than 60 or 90. I think you can understand the problem better from the attached screenshot. 

8 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 05 Mar 2015, 02:50 PM
Hi Ejaz,

What is the type of the data - is it int or string? In case it is string, then all the values will be sorted as strings.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ejaz
Top achievements
Rank 1
answered on 06 Mar 2015, 12:01 PM
Hi Dimitrina,

The data is 'Double'. The itemssource is a DataTable.

Regards,
Ejaz
0
Dimitrina
Telerik team
answered on 06 Mar 2015, 12:32 PM
Hi Ejaz,

RadGridView should sort the column depending on the bound data's type.
As a side note, in that case my recommendation would be to set RadGridView's ItemsSource to be the DataTable.DefaultView. Does this help?
In case not, is it possible for you to isolate the issue you experience in a demo project and send it to us in a new support ticket? You can also take a look at this blog post for a reference on how to isolate an issue. 

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ejaz
Top achievements
Rank 1
answered on 06 Mar 2015, 01:53 PM
Hi Dimitrina,

My license does not include dedicated support, but I would really like to get this problem fixed. I'm posting a sample code in which I've managed to replicated the issue, hope you can help me.

xaml

<Grid>
        <telerik:RadGridView Name="myGridView" AutoGenerateColumns="True"/>
</Grid>

C#

class Data
{
  public string key;
  public string value;
}
 
void Main()
{
   List<Data> data = new List<Data>();
   data.Add(new Data() { key = "one", value = "0"});
   data.Add(new Data() { key = "two", value = "63.78"});
   data.Add(new Data() { key = "three", value = "100"});
   data.Add(new Data() { key = "four", value = "10"});
 
   DataTable dt = new DataTable();
   dt.Columns.Add("key");
   dt.Columns.Add("value");
 
    foreach (Data d in data)
    {
       List<object> ob = new List<object>();
       ob.Add(d.key);
       double value;
       if (double.TryParse(d.value, out value))
         ob.Add(value);
       else
         ob.Add(null);
 
      dt.Rows.Add(ob.ToArray());
    }
    myGridView.ItemsSource = dt;
}


Regards,
Ejaz
0
Dimitrina
Telerik team
answered on 09 Mar 2015, 01:37 PM
Hi,

I tested the shared code and setting the DataTable.DefaultView as an ItemsSource seems to resolve the issue.
For example:
myGridView.ItemsSource = dt.DefaultView;

Let me know how this works for you.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ejaz
Top achievements
Rank 1
answered on 09 Mar 2015, 01:54 PM
Hi Dimitrina,

As I mentioned earlier using DataTable.DefaultView did not fix the issue for me. Is there anything else you could suggest?

Regards,
Ejaz
0
Accepted
Dimitrina
Telerik team
answered on 11 Mar 2015, 03:14 PM
Hello Ejaz,

You are indeed right and I apologize for my confusion. After some further investigation, I can share the following information: checking the data presented in the DataTable, it is always of type string:
 dt.Rows.Add(ob.ToArray()); 
You can set a break point after this line and check that the type of the Value is string. In that case, I am afraid RadGridView will sort it that way. You should either add an object Value or a double Value. In case of populating an object Value, you may need to explicitly set the DataType of the respective GridViewDataColumn.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ejaz
Top achievements
Rank 1
answered on 12 Mar 2015, 06:47 AM
Hi Dimitrina,

I've found the solution to this issue thanks to you. It is like you said, we have to explicitly set the datatype, but not of the GridViewDataColumn but of the DataColumn in the DataTable.

DataTable.Coulmns.Add("Value", typeof(double));

Thanks for all your help.

Regards,
Ejaz
Tags
GridView
Asked by
Ejaz
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Ejaz
Top achievements
Rank 1
Share this question
or