我可以在jqGrid中更改新添加的行的ID吗? [英] Can I change the ID of a newly added row in jqGrid?

查看:309
本文介绍了我可以在jqGrid中更改新添加的行的ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 inlineNav 的jqGrid,以便用户可以在本地编辑/添加/删除行,然后在完成后将所有更改提交给服务器。我希望能够在本地向网格添加多个新行,但由于其他要求,我需要新添加的行具有唯一ID而不是默认 new_row 。此外,由于外键约束,我无法使用ajax调用在添加时立即保留新行。我尝试了以下内容,但ID值没有变化:

I'm using jqGrid with inlineNav so that users can edit/add/delete rows locally and then submit all changes to the server when they are finished. I'd like to be able to add multiple new rows to the grid locally, but due to other requirements, I need the newly added rows to have unique IDs rather than the default new_row. Also, I can't use an ajax call to persist new rows immediately on add due to foreign key constraints. I've attempted the following, but the ID value doesn't change:

<input type="hidden" id="newRowIndex" />

$("#thisGrid").jqGrid('inlineNav', '#thisGridPager', {
    edit: false,
    addtext: "Add",
    save: false,
    cancel: false,
    addParams: {
        position: 'last',
        addRowParams: {
            keys: true,
            oneditfunc: function (rowid) {
                var newRowIndex = $("#newRowIndex").val();
                if (!newRowIndex)
                    newRowIndex = 1;
                $("#thisGrid").jqGrid('setCell', rowid, 'id', rowid + "_" + newRowIndex, '', '');
                newRowIndex++;
                $("#newRowIndex").val(newRowIndex);
            }
        }
    }
});

我只想将新添加的行ID设置为 new_row_1 ,递增每个新添加的行的索引。这是可能的,如果是的话,怎么样?

I would simply like to set the newly added row's ID to new_row_1, incrementing the index for each newly added row. Is this possible, and if so, how?

解决方案

此外对Dean的回答,我发现它在 addRowParams oneditfunc 中不能正常工作。我发现使用jqGrid的 afterInsertRow 事件有效:

In addition to Dean's answer, I discovered that it doesn't work doing it in the oneditfunc of addRowParams. I found that using jqGrid's afterInsertRow event works:

afterInsertRow: function (rowid, rowdata, rowelem) {
    if (rowid == 'new_row') {
        var newRowIndex = $("#newRowIndex").val();
        if(!newRowIndex)
            newRowIndex = 1;
        var newRowId = rowid + "_" + newRowIndex;
        $("#new_row").attr('id', newRowId);
        newRowIndex++;
        $("#newRowIndex").val(newRowIndex);
    }
}


推荐答案

到设置新行的id使用:

To set the new row's id use:

 $("#new_row").attr('id',newId);

参考这个问题:我可以在不重新加载的情况下更改JQGrid中行的主ID吗?

这篇关于我可以在jqGrid中更改新添加的行的ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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