javascript - Kendo Grids Hierarchy Adding New Row - Pass Parent ID to New Child Record -
i new kendo , javascript excuse lapses in knowledge... below have basic kendo hierarchical grid. when try add new record child grid, record gets added via post method in controller parent reference id doesn't passed correctly , instead 0 gets passed foreign key reference child table.
here parent grid
//-----------------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" && 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 testing purposes { field: "log_paperticketisapproved", title: "approved", width: 130, template: "# if(log_paperticketisapproved == 'y') { #" + "# approved = true #" + "# } else { #" + "# approved = false #" + "# } #" + "<input name='paperticketisapproved' class='check_row' type='checkbox' data-bind='checked: approved' #= approved ? checked='checked' : '' #/>" }, { 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&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 testing purposes ] }); var grid = $("#grid").data("kendogrid"); //grid.bind("databound", ondatabound); grid.table.on("click", ".check_row", selectrow) }
and here child grid
//-----------------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----------------- $("<div/>").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}" } ] }); }
what can put in savechanges: desired result? thanks
resolved!!
i found own answer , posting here in hopes may else..
in model of child grid add line of code foreign key reference:
defaultvalue: e.data.log_id
so child grid model looks this
model: { id: "log_commentid", fields: { log_commentid: { type: "number" }, log_id: { type: "number", defaultvalue: e.data.log_id }, log_comment: { type: "string" }, log_commentcreatedby: { type: "string" }, log_commentcreateddate: { type: "date", editable: false } }
Comments
Post a Comment