title: Kendo Grids Hierarchy Adding New Row - Pass Parent ID to New Child Record
body: <p>I am new to kendo and javascript so excuse any lapses in knowledge... Below I have a basic kendo hierarchical grid. When I try to add a new record to the child grid, the record gets added via a post method in my controller but the parent reference ID doesn't get passed correctly and instead 0 gets passed as the foreign key reference to the child table.</p>
  
  <p>Here is my <strong>Parent Grid</strong></p>
  
  <pre><code>        //-----------------KENDO GRID DATA-----------------
      var datasource = new kendo.data.DataSource({
          type: "odata",
          transport: {
              read: {
                  //url: sBaseUrl,
                  url: baseUrl + "StationLogPaperTicketOdata",
                  type: "get",
                  dataType: "json",
                  contentType: "application/json"
              },
              update: {
                  type: "PUT",
                  url: function (data) {
                      return baseUrl + "StationLogPaperTicketOdata(" + data.log_id + ")";
                  },
                  dataType: "json",
              },
              //parameterMap: function(options, operation) {
              //    if (operation !== "read" &amp;&amp; options.models) {
              //    return {models: kendo.stringify(options.models)};
              //    }
              //}
  
          },
  
          schema: {
              data: "value",
              total: function (data) {
                  return data['odata.count'];
              },
              model: {
                  id: "log_id",
                  fields: {
                      log_id: { type: "number" },
                      log_station: { type: "string" },
                      log_sourceCode: { type: "string", nullable: true },
                      log_carrierName: { type: "string", nullable: true },
                      log_ticketNumber: { type: "string", nullable: true },
                      log_deliveryTS: { type: "date" },
                      log_leaseNumber: { type: "string", nullable: true },
                      log_leaseName: { type: "string", nullable: true },
                      log_type: { type: "string" },
                      log_rackNumber: { type: "number", nullable: true },
                      log_logNumber: { type: "number", nullable: true },
                      log_driverFirstName: { type: "string", nullable: true },
                      log_driverLastName: { type: "string", nullable: true },
                      log_linkedTicketNumber: { type: "string", nullable: true },
                      log_volumeGross: { type: "number" },
                      log_volumeNet: { type: "number", nullable: true },
                      log_originalDestination: { type: "string", nullable: true },
                      log_lastModifiedTS: { type: "date", editable: false },
                      log_lastModifiedBy: { type: "string", editable: false },
                      log_meterReadOpen: { type: "number", nullable: true },
                      log_volumeNetCalculated: { type: "number", nullable: true },
                      log_isDeleted: { type: "string", nullable: true },
                      log_detailIsDeleted: { type: "string", nullable: true },
                      log_paperTicketIsApproved: { type: "string", nullable: true, editable: false },
                      log_accountingDate: { type: "date", nullable: true },
                      log_stationNumber: { type: "string", nullable: true },
                      log_isPickup: { type: "string", nullable: true },
                      log_operatorNumber: { type: "string", nullable: true },
                      log_controlNumber: { type: "string", nullable: true },
                      log_dispatchConfirmationNumber: { type: "string", nullable: true },
                      log_groupId: { type: "number", nullable: true },
                      log_groupSource: { type: "string", nullable: true },
                      log_isTank: { type: "string", nullable: true },
                      log_meterReadClose: { type: "number", nullable: true },
                      log_obsTemperature: { type: "number", nullable: true },
                      log_tankTemperature: { type: "number", nullable: true },
                      log_obsGravity: { type: "number", nullable: true },
                      log_bswPercent: { type: "number", nullable: true },
                      log_gaugeBeforeUnloadFeet: { type: "number", nullable: true },
                      log_gaugeBeforeUnloadInches: { type: "number", nullable: true },
                      log_gaugeBeforeUnloadQuarter: { type: "number", nullable: true },
                      log_comments: { type: "string", nullable: true }
                  }
              }
          },
  
          pageSize: 50,
          serverPaging: true,
          serverfilering: true,
          serverSorting: true,
          sort: { field: "log_id", dir: "asc" },
      });
  
      //-----------------KENDO GRID-----------------
  $("#grid").kendoGrid({
          dataSource: datasource,
          pageable:
              {
                  refresh: true,
                  pageSizes: [10,25,50,100],
                  buttonCount: 5
              },
          height: 600,
          width: 500,
          sortable: true,
          scrollable: true,
          reorderable: true,
          toolbar: ["save", "cancel"],
          editable: true,
          filterable: {
              mode: "row"
          },
          selectable: "row",
          resizable: true,
          detailInit: detailInit,
          dataBound: onDataBound,
          columns: [
              //{ field: "log_id", title: "ID", width: 130 }, //THIS IS FOR TESTING PURPOSES
              {
                  field: "log_paperTicketIsApproved",
                  title: "Approved",
                  width: 130,
                  template:
                      "# if(log_paperTicketIsApproved == 'Y') { #" +
                          "# approved = true #" +
                      "# } else { #" +
                          "# approved = false #" +
                      "# } #" +
                      "&lt;input name='paperTicketIsApproved' class='check_row' type='checkbox' data-bind='checked: approved' #= approved ? checked='checked' : '' #/&gt;"
              },
              { field: "log_type", title: "Source", width: 130 },
              { field: "log_rackNumber", title: "Connect Point (LACT)", width: 150 },
              { field: "log_sourceCode", title: "Carrier Source Code", width: 140 },
              { field: "log_carrierName", title: "Carrier Name", width: 130 },
              { field: "log_ticketNumber", title: "Ticket Number", width: 130 },
              { field: "log_deliveryTS", title: "Date", width: 160, format: "{0:MM-dd-yyyy}" },
              { field: "log_deliveryTS", title: "Time", width: 140, format: "{0:hh:mm tt}" },
              { field: "log_volumeGross", title: "Gross BBLs", width: 140 },
              { field: "log_volumeNet", title: "Net BBLs", width: 140 },
              { field: "log_leaseName", title: "Lease Name", width: 200 },
              { field: "log_driverFirstName", title: "Driver First Name", width: 160 }, // template: "#= log_driverFirstName # #=log_driverLastName #" },
              { field: "log_driverLastName", title: "Driver Last Name", width: 160 },
              { field: "log_bswPercent", title: "Obs. BS&amp;W %", width: 140 },
              { field: "log_obsGravity", title: "Obs. Gravity", width: 130 },
              { field: "log_obsTemperature", title: "Obs. Temperature", width: 150 },
              { field: "log_linkedTicketNumber", title: "Linked Ticket Number", width: 150 },
              { field: "log_originalDestination", title: "Original Destination", width: 150 },
              { field: "log_lastModifiedBy", title: "Last Modified By", width: 170 },
              { field: "log_lastModifiedTS", title: "Last Modified Date", width: 170, format: "{0:MM-dd-yyyy hh:mm tt}" },
              //{ field: "log_station", title: "Station", width: 140 } //THIS IS FOR TESTING PURPOSES ONLY
          ]
      });
  
      var grid = $("#grid").data("kendoGrid");
      //grid.bind("dataBound", onDataBound);
      grid.table.on("click", ".check_row", selectRow)
  }
  </code></pre>
  
  <p>and here is the <strong>Child Grid</strong></p>
  
  <pre><code>//-----------------KENDO CHILD-GRID DATA-----------------
  function detailInit(e) {
      var datasource = new kendo.data.DataSource({
          type: "odata",
          transport: {
              read: {
                  url: baseUrl + "StationLogComments",
                  type: "get",
                  dataType: "json"
              },
              update: {
                  type: "put",
                  url: function (data) {
                      return baseUrl + "StationLogComments(" + data.log_commentID + ")";
                  },
                  dataType: "json",
                  contentType: "application/json"
              },
              create: {
                  url: baseUrl + "StationLogComments",
                  type: "post",
                  dataType: "json"
              },
          },
  
          schema: {
              data: "value",
              total: function (data) {
                  return data['odata.count'];
              },
              model: {
                  id: "log_commentID",
                  fields: {
                      log_commentID: { type: "number" },
                      log_id: { type: "number" },
                      log_comment: { type: "string" },
                      log_commentCreatedBy: { type: "string" },
                      log_commentCreatedDate: { type: "date", editable: false }
                  }
              }
          },
          serverPaging: true,
          serverSorting: true,
          sort: { field: "log_commentCreatedDate", dir: "asc" },
          serverFiltering: true,
          width: 100,
          pageSize: 10,
          filter: { field: "log_id", operator: "eq", value: e.data.log_id }
      });
  
  
      //-----------------KENDO CHILD-GRID-----------------
      $("&lt;div/&gt;").appendTo(e.detailCell).kendoGrid({
          dataSource: datasource,
          scrollable: false,
          toolbar: ["create", "save", "cancel"],
          saveChanges: function (e) {
              debugger;
  
          },
          editable: true,
          resizable: true,
          width: 600,
          //sortable: true,
          //pageable: true,
          columns: [
              { field: "log_id", title: "log_id", width: "100px" },
              { field: "log_comment", title: "Comment", width: "500px" },
              { field: "log_commentCreatedBy", title: "Created By", width: "100px" },
              { field: "log_commentCreatedDate", title: "Created Date", format: "{0:MM-dd-yyyy hh:mm tt}" }
          ]
      });
  }
  </code></pre>
  
  <p>What can I put in saveChanges: to get my desired result? Thanks</p>