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

GridView not playing nice with DataAnnotations

6 Answers 60 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel Billingsley
Top achievements
Rank 1
Daniel Billingsley asked on 13 Apr 2010, 05:29 PM
I have a custom business object in which I've used the DisplayAttribute to define the Order I want the items to appear.  (I understand SL4 is embracing the DataAnnotations even more, so this seems a pretty critical thing for a component vendor to get right.)

In the standard Microsoft grid, these values are relative.  That is, I have order values of 0,1,1 and 99 and it just puts the columns in that order (with the order between the middle two being indeterminant, I understand). 

In contrast, the GridView is very VERY picky about this order.  It would seem the technique is to use Insert() or something similar and attempting to use the display order as the literal index of the column.  vs. the Microsoft approach of (apparently) just sorting the column definitions by the order and using the simple Add() then.

While this of course can be solved somewhat by being more careful with the Order values, it still causes a conflict I can't solve between using the DataAnnotations and trying to manually add columns.  There's two problems:

1.  If I only want the 2nd and 3rd column (Order=1 and Order=2) and try to let it determine the order, I get a exception because the first column can't have index of 1.

2. If I try to manually set DisplayIndex to overcome that problem, the GridView seems to still be trying to use the DataAnnotation.  I would expect that setting DisplayIndex means override any other method of determining the order.

6 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 14 Apr 2010, 09:54 AM
Hi Daniel Billingsley,

We are currently in the process of developing a mechanism called DisplayOrder like Microsoft. This will work as you expect, i.e. it will not be zero-based like the index, but will order columns by their order, which can be any number, i.e. 100, 200, 300.

We hope that the fix will be available for the Service Pack coming later this week.

Greetings,
Ross
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
Daniel Billingsley
Top achievements
Rank 1
answered on 14 Apr 2010, 12:13 PM
Then I presume you will switch to making the DataAnnotation Order influence the Telerik DisplayOrder instead of the DisplayIndex, so the AutoGenerate capabilities are in line as well as the manual column creation, right?
0
Rossen Hristov
Telerik team
answered on 14 Apr 2010, 12:41 PM
Hi Daniel Billingsley,

The Order will be simply used to insert an auto-generated column at the correct place. In other words, columns will be ordered by this Order attribute before being auto-generated. The ones that are explicitly defined in XAML will always be to the left of the auto-generated columns.

How does this sound?

Regards,
Ross
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
Daniel Billingsley
Top achievements
Rank 1
answered on 14 Apr 2010, 05:37 PM
That sounds good I think.

For the sake of clarity, I see three general scenarios that must be handled.
1. Complete autogeneration, which should honor the DataAnnotation Order if it exists.
2. Manually designating the columns, but with no DisplayIndex or DisplayOrder given, should also honor the DataAnnotation if it exists. (I only want 3 out of the 5 columns.)
3. Complete manual definition, possibly giving either DisplayIndex or DisplayOrder.

Of course, combinations of all three must be handled.

I didn't investigate every detail, but I'll just say I encourage that all the DataAnnotations are utilized at least as well as the Microsoft controls, including what they are doing in SL4.  The EditableAttribute and TimestampAttribute I know work in SL3 MS grid and DataForm, and I would hope they're going to get DisplayFormatAttribute used in SL4.

What would really be slick  (and I don't know if even MS intends to do all of this) is if there was a flag that could be set to cause some of the attributes to be applied directly to the input controls.  For example, determining the input mask based on the DisplayFormatAttribute or DataTypeAttribute, or limiting the input based on StringLengthAttribute or RangeAttribute.  The control bloat may be too high a cost for these features though.

Thanks for your work on this.
0
Rossen Hristov
Telerik team
answered on 15 Apr 2010, 09:38 AM
Hello Daniel Billingsley,

1. This will be so.

2. This is not the way the MS Grid does it and it will not be the way we will do it. The general rule is the following. If you have any columns defined in XAML (let's call them explicitly defined columns) then they will appear in the order you have defined them. After they are over the auto-generated columns begin and they will honor their Order.

In your scenario you want to show only 3 columns out of 5. You have three different ways to do this:

A) Turn auto-generation off and explicitly define them on the client, i.e. in XAML. You have the full control how to order them. Their Order attribute on the server will be completely ignored, since they will not be aut-ogenerated.

B) Turn auto-generation on. Set the AutoGenerate data annotation to false for the two columns that you do not want to see. This will auto-generate the 3 columns that you want in the Order defined by the data annotation.

C) Turn-auto generation on. Attach to the ColumnAutoGenerating event of the grid and cancel the auto-generation of the two columns that you do not want to see. This will auto-generate the 3 columns that you want in the Order defined by the data annotation.

So you have three different ways to achieve the same thing.

You can try the same thing with the MS DataGrid and you will see that columns that are defined in XAML appear in the order that they were defined and not in the order specified on the server. Auto-generated columns appear after them in the Order defined by their data annotations.

P.S. By the way, you can try the following: Define three columns in XAML for the MS DataGrid. Set their DisplatIndex to 2, 1, and 0 respectively. See what happens.

3. Complete manual definition will simply display the columns as you have defined them.

The bottom line is:

1. The Order attribute is used only for columns that are auto-generated.
2. Auto-generated columns appear after manually defined ones.

Now, once all columns are ready -- you can play with their display indices at runtime. They do not "remember" how they were born, i.e. manually or from auto-generation.

We will investigate the rest of your suggestions.

Thank you for the great feedback.

Kind regards,
Ross
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
Daniel Billingsley
Top achievements
Rank 1
answered on 15 Apr 2010, 12:50 PM
Ross, thanks for all your investigation and reporting.  Everything sounds great!  Sorry for the inaccurate claims about the MS behavior.
Tags
GridView
Asked by
Daniel Billingsley
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Daniel Billingsley
Top achievements
Rank 1
Share this question
or