Skip to navigation
Inline edit with jqgrid and post the data to an api
12.06.19
function set_grid(r) { jQuery("#grid").jqGrid({ colModel:r['col_model'], data : r['data'], rownumbers: true, sortname: "invdate", sortorder: "desc", caption: "Names for the Report", iconSet: "fontAwesome", cmTemplate: { autoResizable: true, editable: true }, inlineEditing: { keys: true, defaultFocusField: "name", focusField: "name", beforeSaveRow: function (o,rowid) { let rd =jQuery(this).jqGrid("getRowData",rowid); update_row(rd); } }, onSelectRow: function (rowid, status, e) { let $self = jQuery(this); let saved_row = $self.jqGrid("getGridParam", "savedRow"); if (saved_row.length > 0 && saved_row[0].id !== rowid) { $self.jqGrid("restoreRow", saved_row[0].id); } $self.jqGrid("editRow", rowid, { focusField: e.target, beforeSaveRow: function (o, rowid) { let rd =$self.jqGrid("getRowData",rowid); update_row(rd); } } ); }, actionsNavOptions: { editbutton: true, delbutton: false } }); } function update_row(doc) { let pairs = []; for (var k in doc) { pairs.push(encodeURIComponent(k) + "=" + encodeURIComponent(doc[k])); } let req = pairs.join("&"); var xhr = new XMLHttpRequest(); xhr.open('POST',url); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.onload = function() { if(xhr.status === 200) { let r = JSON.parse(xhr.responseText); set_grid(r); } else { console.log(xhr.responseText); } }; xhr.send(req); }
https://free-jqgrid.github.io/getting-started/index.html
Reply
Anonymous
Information Epoch 1732639879
Using text data files.
Home
Notebook
Contact us