Grid Functionality stops working after assigning Column DataType

2 posts, 0 answers
  1. Erick
    Erick avatar
    8 posts
    Member since:
    May 2015

    Posted 20 Jul 2015 Link to this post

    Hi all,

     

    I have a RadGrid with autogenerated columns. Everything works fine, except for sorting numbers. The grid tries to sort the numbers as a string, instead of a number. So what I tried to do to get this working, and also be able to get Min/Max/Average/etc, was to change the datatype in the .cs file to Decimal.

     

    Here is what that looks like:

     

    protected void radGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
            {
                if (e.Column is GridBoundColumn)
                {
                    if (e.Column.UniqueName == "Total")
                    {
                        GridBoundColumn col = e.Column as GridBoundColumn;
                        col.DataType = typeof(decimal);
                        col.DataFormatString = "${0:###.##}";
                        col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    }
                }
            }

     

    Now the problem that I am encountering is that the Grid looses all its functionality. I cannot sort any column, I cannot move/hide/filter columns, and I cannot group anything either.

     

    All I see is the Update control spinning for a split second, then it does nothing.

     

    My question is, is this the proper way to assign a datatype to the column (col.DataType = typeof(decimal);) or should be done some other way?

     

    Thanks

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2302 posts

    Posted 22 Jul 2015 Link to this post

    Hello,

    Note that when the columns are auto generated every column is created based on the type of the underlying field. If a column is bound to a numeric field it will be generated as GridNumericColumn. Thus, the data should be sorted as numeric values.

    The above functionality is available out of the box. You do not need to implement custom code to achieve it. You just need to ensure that the DataField is of numeric type.

    For illustration I am attaching a sample project. Give it a try and see how it works for you.

    Regards,
    Viktor Tachev
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top