Reputation: 6228
I'm using free-jqGrid 4.14.1 to display data which has composite ids on two columns: id
and type
. Because jqGrid doesn't support combined keys, I added a field called uniqueId
which contains the concatenated values of id
and type
:
$grid.jqGrid({
url: /*ajaxListURL*/ '',
editurl: /*ajaxActionURL*/ '',
datatype: 'json',
mtype: 'POST',
loadonce: false,
colModel: [
{name: 'uniqueId', key: true, hidden: true}, //uniqueId=id+type
{name: 'id', editable: true, hidden: true, editrules: {edithidden:true}, hidedlg: true},
{name: 'type', editable: true, hidden: true, editrules: {edithidden:true}, hidedlg: true},
{name: 'name', editable: true}
]
}).jqGrid('navGrid', '#pager', {edit: false, add: false, del: true}, {}, {}, {
onclickSubmit: function(options, delId){
var rowData = $(this).jqGrid('getRowData', delId);
return {
id: rowData['id'],
type: rowData['type']
};
}
}).jqGrid('inlineNav', '#pager', {add: false});
My server expects the id
and type
parameters for editing or deleting a record. It cannot handle parsing uniqueId
in order to extract id
without some backend refactoring which I'm trying to avoid.
In order to make the edit work, I made the fields id
and type
editable and hidden, so that jqGrid will send both everytime I am editing a record. (this works fine)
In order to make the delete work, I implemented the onclickSubmit
method of delete pager options, and manually added id
and type
values to the postData. But jqGrid overrides the value of id
with that of the uniqueId
Here is a demo: https://jsfiddle.net/zohalexix/7wczzvur/
Is there anyway to send the actual id
value for the id
parameter when deleting (without renaming parameter id)?
Upvotes: 0
Views: 162
Reputation: 221997
You can solve the problem by adding
prmNames: { id: "uniqueId" }
option of jqGrid. It will inform jqGrid to use uniqueId
instead of default id
for sending of rowids to the server during editing operation.
Additionally you can add one more option
jsonReader: { id: "uniqueId" }
and remove absolutely unneeded hidden column uniqueId
. In general, every hidden DOM element reduce the performance of the page and increase the size of memory used by web browser.
Additionally I'd recommend to remove <div id="pager"></div>
, to use pager: true
instead of pager: '#pager'
and to remove '#pager
parameter from navGrid
and inlineNav
. One can make the code more readable by usage navOptions
, inlineNavOptions
, formEditing
, formDeleting
, searching
, inlineEditing
etc. See https://jsfiddle.net/OlegKi/7wczzvur/26/ an example of the corresponding modification.
Finally, I'd recommend you to migrate to the current 4.15.3 version. I support only the latest version of free jqGrid. If you will find for example a bug in free jqGrid 4.14.1 then it will be fixed only in the latest code (in 4.15.4).
Upvotes: 1