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

The Grid will not create columns for scaffolded = false column

13 Answers 213 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vasile
Top achievements
Rank 1
Vasile asked on 18 Feb 2012, 04:54 PM
After I spent some time searching for the cause of this, I just found that if one property is marked with ScaffoldColumn(false) it will not be considered by the grid at, all even if I explicitly included that column in the Grid column definitions.
I don't think this is the right behavior, I would expect that if I manually add this column to grid definition it shall be included. It shall be ignored because of scaffolding only when I do not specify columns explicitly and you show them all, or in the forms that you create to edit the entities.

Problem is as following:- I need the PK_ID column in the grid because in the onRowSelected event I need the DataKey value of the row, but seems that when using server binding there is no other way to get it but only form a grid cell... so I planned to have this hidden column then, but the Grid will not render it if the PK_ID property is marked with ScaffoldColum(false) I assume if I put that on true .. then the property column will appear aslo in editing forms, or at least will it take in consideration in the editing form that the column is hidden so it shall notappear in the form also?

Any suggestions?

Thanks,
Vasile

13 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 21 Feb 2012, 12:05 PM
Hello Vasile,

Basically you can use the [HiddenInput(DisplayValue=false)] attribute to your model property.
Or you can mark the column as readonly using the Readonly method when declaring the column.
In this case if use edit mode like InLine or InCell the column will be readonly, otherwise you should create custom editor template for your model as shown in this Code Library article.

Kind Regards,
Petur Subev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Vasile
Top achievements
Rank 1
answered on 22 Feb 2012, 12:29 PM
Hello,
Thanks for the hints.

Still besides the workarounds you suggest is it normal the behavior of the grid in this scenario? I mean not allowing to manually add a column if the source is tagged with Scaffold(false) attribute?

Vasile
0
Petur Subev
Telerik team
answered on 22 Feb 2012, 01:14 PM
Hi again Vasile,

Yes, this is by design. A lot of our customers depend on this behavior.

All the best,
Petur Subev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Vasile
Top achievements
Rank 1
answered on 22 Feb 2012, 07:04 PM
Hmm... looks strange to me. I don't see how those customers could be affected by being able to add manually a column or not to the grid.
It is their choice if they would not add it, when the grid adds automaticaly the columns then the Scaffold shall be taken in consideration... this "by design" argument just don't stand in my opinion.

This combined with the fact that supporting the core feature - onRowSelected - demands very obscure workarounds, make me think that this is a side effect and not necessarily a design.

Am I missing something? 
Vasile

0
Atanas Korchev
Telerik team
answered on 27 Feb 2012, 03:56 PM
Hi,

 Actually this is not a decision made by us. According to this blog post ScaffoldColumn = false sets the ShowForDisplay metadata setting to false. Telerik Grid for ASP.NET MVC initializes the column's Visible property from ShowForDisplay.

 One case which you are missing is auto generated columns. ScaffoldColumn = false prevents the Grid from adding all public properties as columns in the grid.

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Vasile
Top achievements
Rank 1
answered on 27 Feb 2012, 04:25 PM
Hello,

Thanks for pointing out the source of this behavior, the blog itself is a very good source of information.
The example you provide is fully correct - the auto generated columns shall always take in consideration the Scaffold attribute (actually the two flags it sets), but in my opinion it shall not be taken in consideration when I want to manually add columns to the grid - and this will not interfere with auto generated columns.
Perhaps you shall think to handle distinctively the two different cases (auto generated and manually added columns), or provide a way to get the DataKey information for the server bound grids on the onRowSelected client event.

Regards,
Vasile
0
Atanas Korchev
Telerik team
answered on 01 Mar 2012, 08:05 AM
Hi,

 I am not sure if we should change this behavior because it would be a breaking change.

 Currently we are serializing the data to which the grid is bound only when editing is enabled. Getting the data key on the client-side when the grid is server-bound requires the data to be serialized always.

Regards,

Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Victor
Top achievements
Rank 1
answered on 30 May 2012, 10:11 AM
Hi,
We just ran into the same issue and I would agree with Vasile that this behaviour is strange. Sure it should be excluded when columns are auto-generated, but when explicitly specifying it feels real strange that they are not shown.

Maybe a reasonable change would be to default them to hidden(true) which could be overridden?

Also - using the suggested  [HiddenInput(DisplayValue=false)] the column is shown but the cell is empty (Server binding). The column is populated correctly when using Ajax binding.

/Victor
0
Atanas Korchev
Telerik team
answered on 30 May 2012, 11:14 AM
Hello,

 Unfortunately we can't really change that behavior. As I said there are people who depend on this feature right now.

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Victor
Top achievements
Rank 1
answered on 30 May 2012, 12:56 PM
Hi again,
I cant really see why people define columns they dont want shown, but I suppose there is a case for that so I respect the decision.

However, the HiddenInput behaviour as described seems to be a bug, right?

Thanks
/Victor
0
Atanas Korchev
Telerik team
answered on 30 May 2012, 01:21 PM
Hello,

 The HiddenInput attribute makes the field render as a hidden input. This is the default ASP.NET MVC behavior which we do not alter in any way.

 What exactly are you trying to achieve with ScaffoldColumn=false?

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Victor
Top achievements
Rank 1
answered on 30 May 2012, 01:40 PM
Hi again,

What I am trying to do is show the Id column in the grid, but have it hidden in the popup editor.

As per your post I changed from ScaffoldColumn(false) to HiddenInput(DisplayValue=false). The grid column shows and the input is hidden, however the content of the Id column is empty when using server binding and shown only when reloading via ajax.

/Victor
0
Atanas Korchev
Telerik team
answered on 30 May 2012, 06:30 PM
Hello,

 The HiddenInput attribute will hide the value when server binding is used. It does not work in ajax binding mode because all display templates don't work there - you need to use a client template to customize the way a column is displayed.

 I think the original topic was discussing a different case. The user wanted to hide a property from the popup editor. That property was not displayed in the grid.

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Vasile
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Vasile
Top achievements
Rank 1
Atanas Korchev
Telerik team
Victor
Top achievements
Rank 1
Share this question
or