Javascript jQGrid,如何在网格内添加新行,而不是通过模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3651585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQGrid, how to add a new row inside the grid, not via a modal?
提问by Moin Zaman
Some quick searching only turns up adding a new row to a jQGridvia a modal popup with the editable fields.
一些快速搜索只会jQGrid通过带有可编辑字段的模式弹出窗口向 a 添加新行。
Can anyone point me to a sample or show me some code that allows you to add a new empty row into the grid itself, at the top?
任何人都可以向我指出一个示例或向我展示一些允许您在顶部的网格本身中添加一个新的空行的代码吗?
I have an action column at the rightmost end of the grid in which onRowSelect()I have a save button appear and I can make that button do the save and refresh the grid I think..
我在网格的最右端有一个操作列,其中onRowSelect()出现一个保存按钮,我可以让该按钮执行保存并刷新我认为的网格。
I can't figure out how to click on a 'Add Row' button and add an empty row inside the grid at the top.
我不知道如何点击“添加行”按钮并在顶部的网格内添加一个空行。
One option that I can see is to style the current add row modal to look like a horizontal row and place it to appear like its a row at the top of the grid.
我可以看到的一个选项是将当前添加行模式设置为看起来像水平行,并将其放置在网格顶部看起来像一行。
jQGrid Documentation: http://www.trirand.com/jqgridwiki/
jQGrid 文档:http: //www.trirand.com/jqgridwiki/
回答by Oleg
If you use datatype:'local' then you can use addRowDatamethod to insert the row with position parameter set to 'first'. See some examples under http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#array_data.
如果您使用 datatype:'local' 那么您可以使用addRowData方法插入位置参数设置为的行'first'。请参阅http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#array_data下的一些示例。
回答by Bob
This answer is courtesy of Oleg in my previous question here:
这个答案是我刚才的问题奥列格的礼节在这里:
use $("#grid").addRowData(rowid,data, position, srcrowid);
使用 $("#grid").addRowData(rowid,data, position, srcrowid);
Inserts a new row with id = rowid containing the data in data (an object) at the position specified (first in the table, last in the table or before or after the row specified in srcrowid). The syntax of the data object is: {name1:value1,name2: value2…} where name is the name of the column as described in the colModel and the value is the value. This method can insert multiple rows at once. In this case the data parameter should be array defined as [{name1:value1,name2: value2…}, {name1:value1,name2: value2…} ] and the first option rowid should contain the name from data object which should act as id of the row. It is not necessary that the name of the rowid in this case should be a part from colModel.
在指定的位置(表中的第一个,表中的最后一个或 srcrowid 中指定的行之前或之后)插入一个 id = rowid 的新行,该行包含 data(一个对象)中的数据。数据对象的语法是: {name1:value1,name2: value2...} 其中 name 是 colModel 中描述的列的名称,value 是值。此方法可以一次插入多行。在这种情况下,数据参数应该是定义为 [{name1:value1,name2: value2...}, {name1:value1,name2: value2...} ] 的数组,第一个选项 rowid 应该包含来自数据对象的名称,它应该作为行号。在这种情况下,rowid 的名称不必是 colModel 的一部分。
P.S. Have a look at my profile for a number of jqgrid questions and answers.
PS 查看我的个人资料,了解一些 jqgrid 问题和答案。

