Home › Forums › Guriddo jqGrid JS › Help › Added row’s ID for refresh
Is there some kind of call back or something that I misssed where I pass some sort of response with the ID of the newly added row back to the browser so that if its edited after being added and the browser not refreshed I don't get an error? I know I can use the reloadAfterSubmit:true but it seems there has to be a better way to do it. I looked through the examples and didn't see it.
add row -> server -> add record -> return new id to browser -> browser updates table with new row ID.
Just now mention, that in the previous question with JSON data you used “userid” instead of “id”. Do you used jsonReader:{id:'userid'} parameter? I updated http://www.ok-soft-gmbh.com/jqGrid/Steffan2-json.htm.
You should verity in IE Developer Tools or in Firebug which ids has
Best regards
Oleg
Using trial and error I found that if I wanted to use “userid” I'd have to change the parameters in my grid constructor. I've changed my code on the backend to just use whatever your plugin sends. I have all that working fine. My question is what do I need to have the server send back to the client? Currently, I have the server sending back the id of the newly created record. For example id:1234 etc. So, what do I need to do on the client (browser) side to grab the new ID and insert it into the table? Will your jsonReader example do that?
Thanks,
Steffan
This is my current constructor:
$(“#navgrid”).jqGrid({
url:appendSession(“/async/users.lasso?x=1”),
datatype: “json”,
hidegrid: false,
colNames:[“User ID”,”First Name”,”Last Name”,”Email”,”Password”,”Groups”,”Notes”,”Admin”],
colModel:[
{name:'id', index:'userid', width:55, editable:false, editoptions:{readonly:true,size:10}, hidden:true},
{name:'firstname', index:'firstname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},
{name:'lastname', index:'lastname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},
{name:'email', index:'email', width:200, editable:true, editoptions:{size:25}, editrules:{email:true, required:true}, resizable:true},
{name:'password', index:'password', width:100, editable:true, editoptions:{size:25}, editrules:{edithidden:true}, hidden:true, resizable:true },
{name:'groups', index:'groups', width:260, editable:true, edittype:”select”, editoptions:{ multiple:true, size:3,
value: $.parseJSON( $.ajax({ url: appendSession('/async/groups.lasso'), type:'post', data: { x:1 }, dataType: 'json', async: false, success: function(data, result) { if (!result) alert('Failure to retrieve the groups.'); } }).responseText)
},
sortable:false, resizable:true},
{name:'notes', index:'notes', width:10, editable:true, edittype:”textarea”, editrules:{edithidden:true}, hidden:true, editoptions:{rows:”3″,cols:”26″}, sortable:false},
{name:'isadmin', index:'isadmin', width:60, editable:true, edittype:”checkbox”, editoptions:{value:”Yes:No”}, align:”center” }
],
rowNum:10,
rowList:[10,20,30],
pager: '#pagernav',
sortname: “userid”,
viewrecords: true,
sortorder: “desc”,
caption:”Users Management”,
editurl:appendSession(“/async/users.lasso?x=2”),
height:210
});
$(“#navgrid”).jqGrid('navGrid','#pagernav',
{}, //options
{height:325,reloadAfterSubmit:false,closeAfterEdit:true,closeOnEscape:true}, // edit options
{height:325,reloadAfterSubmit:false,closeAfterAdd:true,closeOnEscape:true}, // add options
{reloadAfterSubmit:false,closeOnEscape:true}, // del options
{closeOnEscape:true} // search options
);
I'm stuck. Any suggestions?
Oleg,
I've searched the documentation a few times and I'm not seeing any examples of how the data has to be formatted when returning the new ID back to the plugin. Do you have an example? Should it be JSON since I am using datatype: 'json' ? Should it be in the form of {id:1234}?
Thanks,
Steffan
OK Steffan,
The datatype:'json' is not really important for the form editing which you use. Insetad of that the method afterSubmit is what you need to implement because you use
Well, we're getting closer. Its odd. This is what the row looks like inthe Safari element inspector
Notice what the id is. Did I make a mistake in there? I implented the code as you suggested. I don't see a section on the afterSubmit in detail within the wiki to understand the
I supose the error is in my previous code. The afterSubmit should be:
afterSubmit: function(response,postdata) {
Oleg,
Thank you so much!!
For the record, if anyone else gets stuck and this is Google indexed, here is the final constructor!
$(“#navgrid”).jqGrid({
url:appendSession(“/async/users.lasso?x=1”),
datatype: “json”,
hidegrid: false,
colNames:[“User ID”,”First Name”,”Last Name”,”Email”,”Password”,”Groups”,”Notes”,”Admin”],
colModel:[
{name:'id', index:'userid', width:55, editable:false, editoptions:{readonly:true,size:10}, hidden:true},
{name:'firstname', index:'firstname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},
{name:'lastname', index:'lastname', width:100, editable:true, editoptions:{size:25}, editrules:{required:true}, resizable:true},
{name:'email', index:'email', width:200, editable:true, editoptions:{size:25}, editrules:{email:true, required:true}, resizable:true},
{name:'password', index:'password', width:100, editable:true, editoptions:{size:25}, editrules:{edithidden:true}, hidden:true, resizable:true },
{name:'groups', index:'groups', width:260, editable:true, edittype:”select”, editoptions:{ multiple:true, size:3,
value: $.parseJSON( $.ajax({ url: appendSession('/async/groups.lasso'), type:'post', data: { x:1 }, dataType: 'json', async: false, success: function(data, result) { if (!result) alert('Failure to retrieve the groups.'); } }).responseText)
},
sortable:false, resizable:true},
{name:'notes', index:'notes', width:10, editable:true, edittype:”textarea”, editrules:{edithidden:true}, hidden:true, editoptions:{rows:”3″,cols:”26″}, sortable:false},
{name:'isadmin', index:'isadmin', width:60, editable:true, edittype:”checkbox”, editoptions:{value:”Yes:No”}, align:”center” }
],
rowNum:10,
rowList:[10,20,30],
pager: '#pagernav',
sortname: “userid”,
viewrecords: true,
sortorder: “desc”,
caption:”Users Management”,
editurl:appendSession(“/async/users.lasso?x=2”),
height:210
});
$(“#navgrid”).jqGrid('navGrid','#pagernav',
{}, //options
{height:325,reloadAfterSubmit:false,closeAfterEdit:true,closeOnEscape:true}, // edit options
{height:325,reloadAfterSubmit:false,closeAfterAdd:true,closeOnEscape:true, afterSubmit: function(response,postdata) { return [true,””,response.responseText]; } }, // add options
{reloadAfterSubmit:false,closeOnEscape:true}, // del options
{closeOnEscape:true} // search options
);
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top