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

Grid Functionality stops working after assigning Column DataType

1 Answer 9 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erick
Top achievements
Rank 1
Erick asked on 20 Jul 2015, 08:31 PM

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

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 22 Jul 2015, 12:48 PM
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
Tags
Grid
Asked by
Erick
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or