Hi Alex,
Thank you for getting back to me.
I wasn't sure where I should perform the dataSource.insert() and dataSource.sync() calls. I assume it has to be after the transport calls complete, so I changed my dataSource from a remote (wherein each transport operation just specified the URL of the webservice and I used parameterMap to send the appropriate data) to a local datasource, where each transport operation performs an AJAX call to that same webservice. I then added the insert() and sync() call to the success callback for that AJAX call so my code looks as follows:
create:
function
(options) {
//some code removed here that sets some variables to pass to the webservice
$.ajax(
{
url:
"thewebserviceurl"
,
data: {parameter1: parameter1value, parameter2: parameter2value}
},
error:
function
(request, error) {
console.log(error);
},
success:
function
(response) {
try
{
var
results = JSON.parse(response);
var
treelist = $(
"#treelist"
).data(
"kendoTreeList"
);
$.each(results,
function
( i, result ) {
treelist.dataSource.insert(result);
});
treelist.dataSource.sync();
}
catch
(e) {
console.log(e);
}
}
});
}
Once parsed, the JSON returned by the AJAX call will be an array of 3 records which, to use the schema in your example, would look like the below - notice that the IDs are specified in my schema because the records have already been added to the database. Notice also how the latter 2 rows report to the ID of the first row:
{id:101, FirstName: "New", LastName:"Boss", ReportsTo:null}
{id:102, FirstName: "New", LastName:"Subordinate1", ReportsTo:101}
{id:103, FirstName: "New", LastName:"Subordinate1", ReportsTo:101}
My required result is that a new row be added at the root level of the TreeList for "New Boss" and that the 2 rows for the New Subordinates be immediately displayed nested underneath "New Boss".
But the actual result is that all 3 rows are added, non-nested, at the top level of the treelist. Once the operation completes, if I refresh the page with the Treelist on it, the hierarchy all comes up as desired. But I need this to happen without the page refresh, and for the user to then be free to add new subordinates to "New Boss" or even to the New Subordinates via this same process.
Am I doing something wrong that is keeping the records inserted into the datasource from honoring their parent and being drawn in the tree correctly? Or is this unsupported functionality?