如何将jqgrid值提交为formfields? [英] how do I submit jqgrid values as formfields?

查看:218
本文介绍了如何将jqgrid值提交为formfields?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在用户填写传统表单字段(例如用户名,电话等)的表单中使用jqGrid.该表单包含用于订单项的jqGrid,用户可以在其中添加/编辑/删除行以及完成后,提交整个表格.我已经按照自己希望的方式显示了网格,但只是无法将网格的内容作为包含表单的一部分提交.

I am trying to use jqGrid within a form where the user fills out traditional formfields such as username, phone, etc. The form contains a jqGrid for line items where the user can add/edit/del the rows, and when done, submit the entire form. I have the grid working as I want it to appear, I just can't get the contents of the grid submitted as part of a containing form.

这是一个伪代码示例:

<form id="foo">
<input id="username" type="text">Your name<br>
Enter your choices in the grid below:
<!-- imagine jqGrid here -->
<input type="submit" value="Submit the form"></form>

我已经搜索,搜索,阅读了文档,阅读了Wiki等,但是只是看不到如何将jqGrid行和列作为formfields传递.任何指导将不胜感激.

I have searched, googled, read the docs, read the wiki, etc., but just do not see how to pass jqGrid rows and columns as formfields. Any guidance would be appreciated.

推荐答案

可能最好的方法是使用隐藏的表单字段:

Probably the best way to do this would be to use a hidden form field:

<input type="hidden" name="gridData" value="" />

然后,您将在提交表单之前用列数据填充字段.您可以通过在修改网格数据时更新字段来执行此操作,也可以通过按下按钮提交表单时调用JavaScript函数(并在该函数中调用表单submit).

You would then populate the field with column data prior to form submission. You could either do this by updating the field as grid data is modified, or by calling a JavaScript function when the button is pressed to submit the form (and calling form submit from within that function).

要将网格数据写到隐藏字段中,可以依次在网格的每一行上调用getRowData,并将每一行的数据附加到数组中.也许有更好的方法.例如,有一个新的data选项可能有效吗?无论如何,一旦有了网格数据,就可以使用 json2.js 将数据序列化为JSON格式:

To write the grid data out to the hidden field, you could call getRowData successively on each row of the grid, and append data for each row to an array. Or perhaps there is a better way. For example, there is a new data option that might work? Anyway, once you have the grid data you can use json2.js to serialize the data to JSON format:

JSON.stringify( myGridData );

然后在服务器上,您可以从该隐藏字段解码JSON,并进行相应处理.

Then on the server, you can decode the JSON from this hidden field, and process it accordingly.

这篇关于如何将jqgrid值提交为formfields?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆