JqGrid把数据行插入指定位置的方法addRowData

1、首页在colModel里写好方法,如下代码options.rowId是获取当前行的编号

{
   label: '操作',  60, align: 'center', formatter: function (cellvalue, options, rowObject) {
   return '<span><a href="javascript:AddGridRow(' + options.rowId + ')" title="增加行">+</a>&nbsp;&nbsp;&nbsp;<a href="javascript:DelGridRow(' + options.rowId + ')"" title="删除行">-</a></span>'; 
   }
},

2、增加到指定位置的方法如下:

AddGridRow = function (rowId) {
    var $grid = $("#gridTable");
    //在行号序列中获取最大的编号
    var maxRowId = Math.max.apply(Math, $grid.jqGrid('getDataIDs'))
    window.setTimeout(function () {
        $grid.jqGrid("addRowData", maxRowId + 1, rowdata, "before", rowId);
    }, 200);

    //RefreshTotal();
}

注:“addRowData”是根据参数插入一行新的数据,rowid为新行的id,data为新行的数据,position为新增行的位置,srcrowid为新增行的参考位置。position可以为[first,last,before,after],如果是before或者after时需要指定相对的行ID编号

原文地址:https://www.cnblogs.com/firstcsharp/p/8806839.html