重新加载页面后,jqgrid randId()产生重复项 [英] jqgrid randId() produces duplicates after page reload

查看:188
本文介绍了重新加载页面后,jqgrid randId()产生重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网格上,在用户在底行中输入文本之后,我要添加另一行,以便他们可以根据需要填写另一行.网格将根据用户需要增长.这工作正常,但是从db重新加载页面并填充数据库之后,addrowdata()函数不遵循现有的行ID并创建重复项,例如从1开始. jqg1.它应该查看现有的行ID并创建新的唯一ID.因此,如果我已经有5行,则它可能从jqg6开始.这是onCellSelect内部的相关代码:

On my grid, after a user enters text on the bottom row, I am adding another row so they can fill out another row if needed. The grid will grow as needed by the user. This is working fine, however after a page reload and populating from db, the addrowdata() function does not honor existing row ids and creates duplicates, starting from 1 again, e.g. jqg1. It should look at existing row ids and create new unique ids. So if I have 5 rows already, it might start at jqg6. Here is the relevant code inside onCellSelect:

var records = jQuery("#table-1").jqGrid('getGridParam', 'records');
var lastRowId = jQuery("#table-1").jqGrid('getDataIDs')[records - 1];

if (lastRowId == id)
{  
    jQuery('#table-1').addRowData(undefined, {}, 'last');
}


我还尝试了$ .jgrid.randId()而不是未定义的结果,与预期的相同.


I have also tried $.jgrid.randId() instead of undefined, same results as expected.

谢谢

瑞安

推荐答案

我认为错误在于您使用数据库中的数据填充网格的部分.保存在数据库中的数据具有唯一的ID.这些ID是 not ,形式为jqg1,jqg2,...,因此应该没有冲突.您只需要用数据库中的ID填充JSON的id字段即可.

I think that the error is in the part where you fill grid with the data from the database. The data saved in the database has unique ids. The ids are not in the form jqg1, jqg2, ... So if should be no conflicts. You should just fill the id fields of the JSON with the ids from the database.

另一种可能性是,您只需要自己指定addRowDatarowid参数(第一个参数)即可.在这种情况下,您将完全控制网格中添加的行的新ID.

One more possibility is that you just specify the rowid parameter (the first parameter) of addRowData yourself. In the case you will have full control on the new ids of the rows added in the grid.

$.jgrid.randId功能的代码非常简单.有$.jgrid.uidPref初始化为'jqg'$.jgrid.guid初始化为1.$.jgrid.randId函数执行以下操作

The code of $.jgrid.randId function is very easy. There are $.jgrid.uidPref initialized as 'jqg' and $.jgrid.guid initialized to 1. The $.jgrid.randId function do the following

$.jgrid.randId = function (prefix)  {
    return (prefix? prefix: $.jgrid.uidPref) + ($.jgrid.guid++);
}

如果确实需要,则可以增加(但减少)$.jgrid.guid值,而不会产生任何负面影响.

If it is really required you can increase (but not decrease) the $.jgrid.guid value without any negative side effects.

这篇关于重新加载页面后,jqgrid randId()产生重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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