1
votes

I'm working on master/detail page - master records are in a Kendo drop down list and associated detail data is in a kendo grid.

The dd & grid are bound to remote data.

Updating existing grid rows is working fine.

When a new row is saved to the grid, I need to insert the id of the selected drop down item (master record id) and add it to the json data.

My problem is I don't know how to determine if the data being saved is a new record or an edit.

I'm getting this error: "Uncaught TypeError : Cannot read property 'isNew' of undefined"

Thanks for any guidance here.

 $issuegrid
    ->addColumn($issueOwnerCol)
    ->addColumn($issueDescriptionCol)
    ->addColumn($issueDueDateCol)
    ->pageable(false) //this is the toolbar in the footer
    ->height(300)
    ->navigatable(true)
    ->editable(true)
    ->save('onSave')
    ->edit('onEdit')
    **->saveChanges('onSaveChanges')** 
     ->addToolbarItem($igridCreate)
     ->addToolbarItem($igridSave)
     ->addToolbarItem($igridCancel);

Here's the js function:

function **onSaveChanges**(e){

var grid = $("#issuesGrid").data("kendoGrid");
var URL ="/issues/updaterecord.json";
var ddl = $("#woDD").data("kendoDropDownList");
var v = ddl.value();

   if (grid.dataSource.data.model.isNew()){
    alert("New Record")
   }
  grid.dataSource.transport.options.update.url = URL;
  grid.dataSource.sync();
 }
1

1 Answers

0
votes

Well, it's a workaround, but in my onSaveChanges function, I had to append the required id to the create url and then extract the it on the server. I would have preferred to just add a key/value pair to the json payload.

function onSaveChanges(e){
    var grid = $("#issuesGrid").data("kendoGrid");
    var ddl = $("#woDD").data("kendoDropDownList");    
    var woID = ddl.value();
    var createURL ="/issues/addrecord.json?woID=" + woID;

    grid.dataSource.transport.options.create.url = createURL;

     //when updating an edited record, transport will use the default url defined in php code.              

}