Problem with ordering and filtering

9 posts, 1 answers
  1. Ejaz
    Ejaz avatar
    9 posts
    Member since:
    May 2014

    Posted 05 Mar 2015 Link to this post

    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. 
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 05 Mar 2015 Link to this post

    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.

     
  3. Ejaz
    Ejaz avatar
    9 posts
    Member since:
    May 2014

    Posted 06 Mar 2015 in reply to Dimitrina Link to this post

    Hi Dimitrina,

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

    Regards,
    Ejaz
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Mar 2015 Link to this post

    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.

     
  5. Ejaz
    Ejaz avatar
    9 posts
    Member since:
    May 2014

    Posted 06 Mar 2015 in reply to Dimitrina Link to this post

    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
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Mar 2015 Link to this post

    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.

     
  7. Ejaz
    Ejaz avatar
    9 posts
    Member since:
    May 2014

    Posted 09 Mar 2015 in reply to Dimitrina Link to this post

    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
  8. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 11 Mar 2015 Link to this post

    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.

     
  9. Ejaz
    Ejaz avatar
    9 posts
    Member since:
    May 2014

    Posted 12 Mar 2015 in reply to Dimitrina Link to this post

    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
Back to Top