jqGrid: how to update row id if primary key column

2019-03-05 06:21发布

Primary key values are used as row ids in json data returned from server. If primary key value is edited and saved two times, second save causes error since jqGrid passes original primary key value again to edit method.

How to update jqGrid row id to new primary key value if primary key value is changed in inline editing ?

$(function () {
        var grid = $("#grid");
        grid.jqGrid({
                url: '<%= ResolveUrl("~/Grid/GetData?_entity=Strings")%>',
                datatype: "json",
                mtype: 'POST',
                scroll: 1,
                autoencode: true,
                colModel: [{
                    name: 'Source',
                    fixed: true,
                    editable: true,
                    width: 30
                }, { /* this is primary key passed also as id */
                    name: 'Est',
                    fixed: true,
                    editable: true,
                    width: 271
                }, {
                    name: 'Eng',
                    fixed: true,
                    editable: true,
                    width: 167
                }],
                gridview: true,
                pager: '#pager',
                viewrecords: true,
                editurl: '<%= ResolveUrl("~/Grid/Edit?_entity=Strings")%>',
        ...

标签: jquery jqgrid
2条回答
Root(大扎)
2楼-- · 2019-03-05 06:56

The rowid is nothing more as the value of id attribute of the corresponding <tr> element of the grid. So to change the rowid oldRowid to newRowid you should do something like the following:

$("#" + oldRowid).attr("id", newRowid);
查看更多
小情绪 Triste *
3楼-- · 2019-03-05 06:57
#gridPreSeleccion = id grid
grid multiselect=true
function eliminarSeleccionados() {
    var idsContribuyentesSelect = jQuery("#gridPreSeleccion").jqGrid('getGridParam', 'selarrrow');
    if(idsContribuyentesSelect.length == 0) {
        jQuery.MessageAlertSath("Es necesario seleccionar una fila.")
    } else {
        var ids = jQuery("#gridPreSeleccion").jqGrid('getDataIDs');
        var a = ids.length;
        var j = 0;
        while(j == 0) {
            if(jQuery("#gridPreSeleccion").jqGrid('getGridParam', 'selarrrow').length <= 0) {
                j = 1;
            } else {
                for(var i = 0; i < a; i++) {
                    if(idsContribuyentesSelect[0] == ids[i]) {
                        jQuery('#gridPreSeleccion').delRowData(ids[i]);
                        break;
                    }
                }
            }
        }
    }
}
查看更多
登录 后发表回答