jqGrid本地数据操作;(jqGrid local data manipulation; problem with row ids when deleting and adding new rows

编程入门 行业动态 更新时间:2024-10-26 12:35:46
jqGrid本地数据操作;(jqGrid local data manipulation; problem with row ids when deleting and adding new rows)

我正在使用jqGrid作为客户端网格输入,允许用户在一次性回发所有数据之前输入多个记录。

我有一个问题,如果用户添加了一些记录(比如3),记录的id将是1,2,3。 如果用户删除了记录2,那么你将留下1和3作为记录的id。

当用户现在添加新记录时,jqGrid会再次分配记录id 3,因为它似乎只计算总记录数并将其增加一个用于新记录。 选择行时会出现问题,因为现在行ID是1,3和3。

有没有人知道如何访问记录的行ID,因为我可能使用afterSubmit事件并重新分配行ID从1开始增加(因此在删除行ID 2之后,这将把另一行id设置为1和2)

还有其他建议可以解决这个问题吗?

谢谢

编辑我用删除navGrid按钮的以下代码解决了这个问题

}).navGrid('#pager', {add:true, del:true, refresh:false, search:false}, { ... }, ##edit parameters { ... }, ##add parameters {reloadAfterSubmit:false, clearAfterAdd:false, afterComplete: function () { ## clear and readd the row data so the row ids are sequential var savedData= $("#inputgrid").jqGrid('getRowData'); $("#inputgrid").jqGrid('clearGridData'); $("#inputgrid").jqGrid('addRowData', 'rn', savedData); } } ##delete parameters );

基本上只是保存网格数据,然后重新添加它,以便rowid再次顺序。

由于某种原因,它会导致左侧的行号从2开始而不是从1开始。 使用GitHub中最新的jqGrid代码(2010年4月27日)解决了这个问题。 但我发现当你试图编辑行时,那个版本的jquery.fmatter.js导致空单元格显示“”,所以我不得不将该文件恢复为jqGrid 3.6.4中的文件。

I'm using jqGrid as a client side grid input, allowing the user to input multiple records before POSTing all the data back at once.

I'm having a problem where if the user has added a few records (say 3 ) the id's for the records will be 1,2,3. if the user deletes record 2, you're left with 1 and 3 for the id of the records.

When the user now adds a new records, jqGrid assigns that records the id 3 again since it just seems to count the total records and increments it by one for the new record. This causes problems when selecting rows as now the row id's are 1, 3 and 3.

Does anyone know how to access the row ids of records as I could probably use the afterSubmit event and reassign the row id's increasing from 1. ( so after i delete row id 2, this will set the other row id's to 1 and 2)

Any other suggestions to solve this problem?

Thanks

edit I've solved this with the following code for the delete navGrid button

}).navGrid('#pager', {add:true, del:true, refresh:false, search:false}, { ... }, ##edit parameters { ... }, ##add parameters {reloadAfterSubmit:false, clearAfterAdd:false, afterComplete: function () { ## clear and readd the row data so the row ids are sequential var savedData= $("#inputgrid").jqGrid('getRowData'); $("#inputgrid").jqGrid('clearGridData'); $("#inputgrid").jqGrid('addRowData', 'rn', savedData); } } ##delete parameters );

Basically just saving the grid data and then re-adding it so that the rowids are sequential again.

For some reason it causes the row numbers down the left side to go start from 2 instead of one. Edit this was solved by using the latest jqGrid code in GitHub (27th April 2010). But I found out that that version of jquery.fmatter.js caused empty cells to show " " when you tried to edit the row so I had to revert that file back to the one in jqGrid 3.6.4.

最满意答案

解决了问题的编辑部分中指出的问题

Solved as indicated in the edit section of the question

更多推荐

本文发布于:2023-08-07 20:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   数据   data   manipulation   jqGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!