Problem with Editable method for bool column

7 posts, 0 answers
  1. John
    John avatar
    4 posts
    Member since:
    Jul 2015

    Posted 05 Aug 2015 Link to this post

    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

  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1443 posts

    Posted 07 Aug 2015 Link to this post

    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
  3. John
    John avatar
    4 posts
    Member since:
    Jul 2015

    Posted 07 Aug 2015 in reply to Alexander Popov Link to this post

    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

     

  4. John
    John avatar
    4 posts
    Member since:
    Jul 2015

    Posted 10 Aug 2015 in reply to Alexander Popov Link to this post

    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

  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1443 posts

    Posted 11 Aug 2015 Link to this post

    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
  6. John
    John avatar
    4 posts
    Member since:
    Jul 2015

    Posted 11 Aug 2015 in reply to Alexander Popov Link to this post

    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.  
  7. Alexander Popov
    Admin
    Alexander Popov avatar
    1443 posts

    Posted 13 Aug 2015 Link to this post

    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
Back to Top