Below is my requirement:
Initially JQgrid should be Empty
On click of Jqgrid an new row has to be added with auto ID
On lost focus of row data should be saved to DB
On click of row user should be able to edit it and on lost focus data should be saved to DB
var lastsel; jQuery("#list").jqGrid({ url: "/TransactionType/GetGridData/", datatype: 'json', mtype: 'GET', height: "300", colNames: ['Customer ID', 'Contact Name', 'Address', 'City', 'Postal Code'], colModel: [ { name: 'CustomerID', index: 'CustomerID', width: 100, align: 'left' }, { name: 'ContactName', index: 'ContactName', width: 150, align: 'left', editable: true }, { name: 'Address', index: 'Address', width: 300, align: 'left', editable: true }, { name: 'City', index: 'City', width: 150, align: 'left', editable: true }, { name: 'PostalCode', index: 'PostalCode', width: 100, align: 'left', editable: true } ], pager: jQuery('#pager'), rowNum: 10, rowList: [1, 3, 5, 10, 20, 30, 40, 50], recordpos: 'right', viewrecords: true, sortorder: "desc", sortname: "CustomerID", sorttype: "integer", multiselect: false, caption: "Manipulating JSON Data", emptyrecords: "No records found.", loadtext: "Loading...", loadonce: true, pgtext: "Page {0} of {1}", jsonReader: { repeatitems: true, cell: "cell" }, onSelectRow: function (id) { if (id) { if (id !== lastsel) { jQuery('#list').jqGrid('restoreRow', lastsel); jQuery('#list').jqGrid('editRow', id, true); lastsel = id; } else { jQuery('#list').jqGrid('restoreRow', lastsel); lastsel = ""; debugger; var rows = jQuery("#list").jqGrid('getRowData'); var paras = new Array(); for (var i = 0; i < rows.length; i++) { var row = rows[i]; paras.push($.param(row)); } var rids = $('#list').jqGrid('getDataIDs'); var n = rids.length; var nth_row_id = rids[n - 1]; jQuery("#list").addRow(n + 1, parameters = { edit: true, editicon: "ui-icon-pencil", add: true, addicon: "ui-icon-plus", save: true, saveicon: "ui-icon-disk", cancel: true, cancelicon: "ui-icon-cancel", addParams: { useFormatter: false }, editParams: {} }); } } }, editurl: "/TransactionType/GetTotalCount", });
This is my Jqgrid where i'm able to add the row but not with auto generated id and I'm not able to call the controller method after lost focus of row or Enter key.