Grid with column bound to null complex property

7 posts, 0 answers
  1. Nick
    Nick avatar
    4 posts
    Member since:
    Nov 2012

    Posted 10 Dec 2012 Link to this post

    With this data:
    var fails = 
    [
      { id: 0, name: 'zero', complex: { name: 'complex 0' } },
      { id: 1, name: 'one', complex: null }
    ];

    And these columns:
    var columns = 

      { title: "id", field: "id" },
      { title: "name", field: "name" },
      { title: "complex", field: "complex.name" }
    ];

    This throws an exception and fails to render any data:
    $("#fails").kendoGrid({
      dataSource: fails,
      columns: columns
    });

    JSBin demo here: http://jsbin.com/omuviw/3/edit
  2. Marcin Butlak
    Marcin Butlak avatar
    26 posts
    Member since:
    Dec 2012

    Posted 10 Dec 2012 Link to this post

    Why should it not throw an error when you are trying to display object property complex.name when complex is null?
  3. Kendo UI is VS 2017 Ready
  4. Nick
    Nick avatar
    4 posts
    Member since:
    Nov 2012

    Posted 10 Dec 2012 Link to this post

    Perhaps it is my job to make sure my data is ok, but I was hoping to fall into the Pit Of Success.

    What could I possibly mean when I ask the grid to display the name property of a null reference?

    I certainly don't want the grid to throw a hissy fit ( and a js exception ) and refuse to render any of the data.

    Ideally, I would like the grid to treat the expression as a null value.
    Other components I have used do this and it works well.
  5. Marcin Butlak
    Marcin Butlak avatar
    26 posts
    Member since:
    Dec 2012

    Posted 10 Dec 2012 Link to this post

    I think that the data should be strict bound to field/property names, because it is easier to debug. The point of using a widget is to ease some tasks not to mask an important error.
  6. Nick
    Nick avatar
    4 posts
    Member since:
    Nov 2012

    Posted 10 Dec 2012 Link to this post

    In my use case, null property objects are not an error - they are part of the domain model.

    I just want to throw an object graph at the grid and have it displayed with all the goodness: themeing, paging, filtering, grouping, sorting...

    My data comes from Entity Framework and contains foreign key property objects that may be null.
    I don't want to use View Models for basic CRUD pages - they shouldn't be required and just add complexity.
  7. Marcin Butlak
    Marcin Butlak avatar
    26 posts
    Member since:
    Dec 2012

    Posted 10 Dec 2012 Link to this post

    I understand that but you must remember that you are working here with client <-> server/local data configuration. The client knows that it will recieve some data structure it doesn't know how to handle it. There is always some logic involved... I think that MVVC or MVC clearly defines which goes where. And too much magic is always bad from my point of view. I think that putting some simple logic statements in field data to handle the null values isn't a bad approach. Another way would be to define the model source but I don't know how complex the model source in kendoui is.
  8. Cody
    Cody avatar
    12 posts
    Member since:
    May 2013

    Posted 24 Jul 2013 Link to this post

    I agree with Nick on this. A simple solution for your customers would be to have the grid not fail. If we want to handle the binding problem we can using a manner you suggest.

     I got around it by doing this in the requestEnd event.

    requestEnd: function (e) {
        var response = e.response;
        $.each(response, function (index, value) {
            if (value.Magazine == null) {
                value.Magazine = {Id:"",Name:""}
            }
        });
    }
Back to Top
Kendo UI is VS 2017 Ready