似乎有很多解决方案非常接近解决我的问题,但在我提出的数十个问题中,似乎没有一个能够完全解决我想要做的事情。尽管我看到几乎同样的问题没有得到答案。我尝试了很多选项和功能的组合,但都无济于事。
我想使用模态表单将包含输入值的新行添加到 jqGrid,但我不希望它在提交时发布到服务器。我确实想最终发布到服务器,但只有在客户端用户对从模式表单添加的行执行额外编辑(如果需要)之后。在客户端执行一些编辑(进而动态更新其他列)之前,我不希望将任何行保存到远程数据库。一旦验证了值的特定状态,就会显示“保存”按钮,并且可以将网格行发布到服务器。除非满足此验证条件,否则不会将行提交到数据库。我在我的应用程序的其他地方使用了许多 jqGrid,它们确实发布了提交的模式表单的新行数据,但是我试图在这个网格中完成一些与客户端不同的事情,而客户端不会立即涉及服务器。我喜欢模式表单的更直观的界面,用于与客户端用户初始输入值,然后在需要时编辑内联新行的字段,这就是我的问题所必需的:我可以仅将表单作为新行提交吗?发生向服务器发送任何操作吗?
我在 jqGrid Wiki 资源中看到用户发表的评论,他说如果“clientArray”是为使用 Grids 模态表单提交选项而输入的值“editurl:”clientArray”,则模态表单不会吐出“未设置 URL” ”消息,但它仍然存在,并且新行未添加到网格中。我已将网格数据类型设置为本地“数据类型:'clientSide'”,但得到相同的“未设置 URL”错误消息。脚本是对于由自定义按钮调用的模态表单来说非常简单,如下所示:(
“footerrow、userDataOnFooter 和 altRows”选项作为摘要页脚中更新值的一部分包含在内,这与对新的单元格执行的编辑有关通过模态形式添加行)
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
})
});
我希望这相当清楚,使用模态形式添加一行而不立即发布到服务器应该相当简单,但我无法找到解决方案。如果我没有立即单击图标以获得正确的答案,请耐心等待,但当我知道要单击什么时,我会这样做,因此请相应地提出建议。 :)
非常感谢。
杰瑞
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
发布评论
评论(2)
当前版本的表单编辑不支持本地数据类型。尽管如此,我们还是可以用更长一点的代码来实现。我不久前创建了演示并发布了这里是在 jqGrid 中实现本地编辑支持的建议。目前还没有实现,但是你可以使用我的例子来实现你需要的。
我包含以下代码:
更新:代码更改为与我在 答案中发布的 jqGrid 4.4.1 一起使用。
更新2:答案提供4.5.4的更新。
更新3:新的4.7版本的jqGrid现在支持本地数据的表单编辑。使用新版本的相应演示位于此处。我只需添加
formatter: "date"
的新reformatAfterEdit: true
选项。 另一个演示使用jqGrid 4.6。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.编辑
作为
4.3.2
,网格的行为与
4.3.1
和
4.3.2
发生了变化,否则网格返回 url 错误
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