There appear to be many solutions that are very close to addressing my problem but of the dozens and dozens of questions I've poured through not one seems to exactly address what I'm trying to do. Although I have seen nearly the same question asked without an answer. I have tried so many combinations of options and functions to no avail.
I want to use the modal form to add a new row with the inputted values to the jqGrid but I do not want it to post to the server upon Submit. I do want to eventually post to the server but only after the client user has performed additional editing (if needed) on the row(s) added from the modal form. I do not want any rows saved to the remote database until the client has performed some edits which in turn dynamically update other columns. Once a certain status of values are validated then a Save button is displayed and the Grid row(s) can be posted to the server. Unless this validated condition is met the row(s) are not to be submitted to the database. I have a number of jqGrids in use elsewhere in my app which do post the new row data of a submitted modal form but this grid I'm trying to accomplish something different with the client which doesn't immediately involve the server. I like the more intuitive interface of the modal form for the initial entry of values with the client user then editing inline the fields of the new row if needed which is what has necessitated my question: can I submit the form as a new row only without any posting action to the server occurring?
I saw in the jqGrid Wiki resource a comment made by a user who said if "clientArray" is the value entered for use the Grids modal form submission option "editurl: "clientArray" that the modal form would not spit the "No URL is set" message but it still does and a new row is not added to the grid. I've made the Grid datatype as a local "datatype: 'clientSide'" but get the same "No URL is set" error message. The script is pretty straightforward for the modal form which is invoked by a custom button as follows:
(The "footerrow, userDataOnFooter and altRows" options are included as part of the values updating in a summary footer which is related to editing performed upon the cells of the new row(s) being added through the modal form)
jQuery("#grid_test").jqGrid({
url:'/grid_test_url.asp?id=' + vId,
datatype: "clientSide",
colNames: ['ID','Col 1', 'Col 2', 'Col 3','Col 4'],
colModel: [
{name:'id',index:'id',width:90,align:"center",editable:true,editoptions:{size:25}, formoptions: {...}, editrules: {...}},
{name:'col1',index:'col1',width:130,align:"right",editable:true,editoptions:{size:25}, formoptions: {}, editrules: {}},
{name:'col2',index:'col2',width:130,align:"right",editable:true,editoptions:{size: 25}, formoptions: {}, editrules: {}},
{name:'col3',index:'col3',width:130,align:"right",editable: true,editoptions:{size:25}, formoptions: {}, editrules: {}},
{name:'col4',index:'col4',width:130,align:"right",editable:true,editoptions:{ size: 25 }, formoptions: {}, editrules: {}}
],
rowNum:5,
rowList:[5,10,20],
pager: '#pgrid_test',
toolbar: [true, "top"],
editurl: '', //not sure what would go here to block attempted post by the Submit action of the modal form
width: 500,
sortname: 'id',
viewrecords: true,
sortorder: "asc",
multiselect: true,
cellEdit: true,
caption: "Grid Test Add New Row",
footerrow: true,
userDataOnFooter: true,
altRows: true
})
jQuery("#grid_test").jqGrid('navGrid', '#pgrid_test', { add: false, edit: false, del: false })
//append custom button
$("#t_grid_test").append("<input type='button' class='add' value='Add New Row' style='height:20px; color:green; font-size:11px;' />");
$("input.add", "#t_grid_test").click(function () {
jQuery("#grid_test").jqGrid('editGridRow', "new", {
jqModal: true,
savekey: [true, 13],
navkeys: [true, 38, 40],
bottominfo: "Fields marked with (*) are required. ",
addCaption: 'New Row Values',
width: 300,
dataheight: 200,
recreateForm: true,
//checkOnUpdate: true,
//checkOnSubmit: true,
//reloadAfterSubmit: true,
closeOnEscape: true,
closeAfterAdd: true
//clearAfterAdd: true
})
});
I hope this is reasonably clear. It seems it should be rather simple to add a row using the modal form without it immediately posting to the server but I cannot work out the solution. And please bear with if I don't promptly click the icons for the proper credit given for answers but I will when I know what to click so please advise accordingly. :) Many thanks in advance. Jerry
EDIT as
4.3.2
there is a change in behavior of the Gridwith
4.3.1
with
4.3.2
otherwise the grid return the url error
The current version of the form editing don't support local datatype. Nevertheless one can do implement if with a little more long code. I created the demo some time ago and posted here the suggestion to implement the local editing support in jqGrid. Till now it is not yet implemented, but you can use my example to implement what you need.
I include the code below:
UPDATED: The code change to work with jqGrid 4.4.1 I posted in the answer.
UPDATED 2: The answer provide update for 4.5.4.
UPDATED 3: New 4.7 version of jqGrid supports now form editing of local data. The corresponding demo which uses the new version is here. I need just add new
reformatAfterEdit: true
option offormatter: "date"
. Another demo uses jqGrid 4.6.