Reputation: 1759
I just spent 4 days working out how to do this as it is not in the documentation and I could not get any support from Telerik, even though I am a paying customer that lodged support tickets on this issue. To be fair to Telerik I think this was due to one very poor support tech, they are usually pretty good. Telerik if you reading check out ticket numbers: 964961, 962272. Let's hope for a better response next time.
In the hope that this saves someone else 4 days... here is the problem I had and how I fixed it.
I was doing a load on demand scenario with the Kendo TreeList. We have our own request manager that handles all transactions with the server, so we use a JS function on the read transport for the Kendo dataSource, and use options.success(aData), to put the data returned from the server into the dataSource.
We have PHP routes which call MySQL procs, and MySQL returns everything as a string, so when PHP converts the results into JSON, all non null values are sent as strings. This includes the hasChildren field.
Normally this is not a problem as the Kendo dataSource will type the values correctly according to the types defined in the dataSource Schema. However I found that after the data was assigned to the dataSource, all the hasChildren: "true", values would get converted to hasChildren: false and as a result no expand buttons would show on the TreeList for the load on demand items that had children.
So I needed a way to map the hasChildren field to a typed field so the conversion from string to bool would happen.
Here what I finally got to work:
"OpParent": {
"type": "number",
"nullable": true
},
"parentId": {
"type": "number",
"field": "OpParent",
"defaultValue": null
},
"OpHasChildren": {
"type": "boolean",
"nullable": true
},
"hasChildren": {
"type": "boolean",
"field": "OpHasChildren"
}
I also found that if your root level parent has a value of null, you need to set the defaultValue to null in the parentID definition.
Hopefully this will save someone the time it took to work this out.
Telerik, please put this in the documentation!!
Regards,
Scott
Upvotes: 0
Views: 1621
Reputation: 1759
The question was the answer ;-)
But for those that want to see the answer in the answer.... here it is:
Here what I finally got to work:
"OpParent": {
"type": "number",
"nullable": true
},
"parentId": {
"type": "number",
"field": "OpParent",
"defaultValue": null
},
"OpHasChildren": {
"type": "boolean",
"nullable": true
},
"hasChildren": {
"type": "boolean",
"field": "OpHasChildren"
}
I also found that if your root level parent has a value of null, you need to set the defaultValue to null in the parentID definition.
Hopefully this will save someone the time it took to work this out.
Upvotes: 0