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
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
6 Answers, 1 is accepted
0
Marcin Butlak
Top achievements
Rank 2
answered on 10 Dec 2012, 02:53 PM
Why should it not throw an error when you are trying to display object property complex.name when complex is null?
0
Nick
Top achievements
Rank 1
answered on 10 Dec 2012, 03:19 PM
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.
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.
0
Marcin Butlak
Top achievements
Rank 2
answered on 10 Dec 2012, 03:51 PM
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.
0
Nick
Top achievements
Rank 1
answered on 10 Dec 2012, 04:19 PM
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.
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.
0
Marcin Butlak
Top achievements
Rank 2
answered on 10 Dec 2012, 11:24 PM
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.
0
Cody
Top achievements
Rank 1
answered on 24 Jul 2013, 04:33 PM
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.
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:
""
}
}
});
}