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

Problem with Editable method for bool column

6 Answers 563 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 05 Aug 2015, 02:02 PM

I have a simple grid w/ ajax binding and some nested grids, all i want to do is have an inline edit for one field and set the other 2 to readonly.  One of the fields is a bool and when i set Editable(false) in the datasource model i get an exception saying that the value passed to the dictionary is null but with Editable(true) or no Editable call it works fine.  The RequireAll bool shouldnt be changeable in this grid, its just there for reference.  

 

@(Html.Kendo().Grid<ScheduleQual>().BindTo(Model.Quals)
          .Name("grid")
          .Columns(columns =>
          {
              columns.Bound(p => p.Qual.Name).Title("Name");
              columns.Bound(p => p.Id).Hidden();
              columns.Bound(p => p.Qual.RequireAll);
              columns.Bound(p => p.Required);
          })
          .Editable(editable => editable.Mode(GridEditMode.InCell))
          .Pageable()
          .Sortable()
          .ClientDetailTemplateId("template")
          .Scrollable(scr => scr.Height(430))
          .DataSource(dataSource => dataSource
              .Ajax()
              .Batch(true)
              .PageSize(20)
              .Model(model =>
              {
                  model.Id(p => p.Id);
                  model.Field(p => p.Qual.Name).Editable(false);
                  model.Field(p => p.Qual.RequireAll);//this is the field i want to make readonly
                  model.Field(p => p.Required).DefaultValue(0).Editable(true);
              })
              .Read(read => read.Action("HierarchyBinding_Quals", "Scheduling"))
           )
          .Events(events => events.DataBound("dataBound"))
              )

Maybe i'm just doing something wrong, i just started using these controls.  

 

As a side note i've noticed that sometimes the RequireAll column renders as 'true'  or 'false' and sometimes with a green icon that says Yes.  is it possible to force the icon style to display when readonly instead of the true false?

 

John

6 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 07 Aug 2015, 08:05 AM
Hi John,

I would suggest specifying a default value for the Qual field, so that the nested properties are created. Otherwise they are undefined when adding new item to the Grid, which might lead to some errors. Once you do that setting their Editable option to false should be enough to get the desired results. Another approach you can try is using a Template instead of a Bound column. This will allow you to render the value only, both when in read and in editing mode.

Regards,
Alexander Popov
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
0
John
Top achievements
Rank 1
answered on 07 Aug 2015, 12:48 PM

The qual field is defined its passed as the model to the view, its only the RequireAll field that causes the issue.  I thought .BindTo(Model.Quals) was supposed to tell the grid to use that for data until it has to refresh.

 

Here is the exception

An exception of type 'System.InvalidOperationException' occurred in System.Web.Mvc.dll but was not handled in user code

Additional information: The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Boolean'.

i also changed the model.Field line to  model.Field(p => p.Qual.RequireAll).DefaultValue(false).Editable(false); which still causes the above exception, it doesnt cause any problem when the .Editable is removed or is passed true.  Let me know if i did something wrong the Editable method works on other fields i cant believe i'd have to make a template for just a bool column.

John

 

0
John
Top achievements
Rank 1
answered on 10 Aug 2015, 10:35 PM

I've tried a few things to fix this issue and so far nothing has worked.  

i changed the column declaration to the following

columns.Bound(p => p.Qual.RequireAll).Title("Require All?").ClientTemplate(
                            "#if (Qual.RequireAll) {#" +
                               "<span class='label label-success'>Yes</span>" +
                            "#} else {#" +
                               "<span class='label label-important'>No</span>" +
                            "#}#").EditorTemplateName("ReadOnlyBool");

That fixes my display issue when not editing, however adding the EditorTemplateName still causes the exception.  ReadOnlyBool is a edit template that i defined.   I've gone through every constructor and ajax call and verified that the RequireAll and Qual items always have at least a non null default value.  Any thoughts would be appreaciated

0
Alexander Popov
Telerik team
answered on 11 Aug 2015, 11:22 AM
Hello again John,

Resolving the data type of the nested properties is not supported, so they are all treated as strings. In this case you could use a flattened ViewModel or create a Template column to avoid using editing the field at all. For example: 
columns.Template(p => { }).ClientTemplate("#=Qual.RequireAll#");

Regards,
Alexander Popov
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
0
John
Top achievements
Rank 1
answered on 11 Aug 2015, 03:09 PM
It seems to know what the type is, it keeps rendering my custom boolean editor, and i got the client template working for the bool display.  Since using EditorTemplateName sends a null to the editor, and Editable(false) requires a value which doesnt make sense to me but is what it is. Is there a way i can block, override,  or unwire whatever event that triggers the changeover to edit mode so i can just leave the ClientTemplate displayed all the time.  
0
Alexander Popov
Telerik team
answered on 13 Aug 2015, 09:09 AM
Hello,

As I mentioned, you could use a Template instead of a Bound column. This will make the field non-editable and as a result only the ClientTemplate will be shown. Another approach you could try is to use MVVM binding in the EditorTemplate, should you decide to leave the column Bound. Here is a video illustrating the scenarios.

Regards,
Alexander Popov
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
John
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
John
Top achievements
Rank 1
Share this question
or