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
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

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
Yes, this is by design. A lot of our customers depend on this behavior.
Petur Subev
the Telerik team

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
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

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
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,
the Telerik team

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
Unfortunately we can't really change that behavior. As I said there are people who depend on this feature right now.
Atanas Korchev
the Telerik team

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
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?
Atanas Korchev
the Telerik team

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
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.
Atanas Korchev
the Telerik team