how to add new row in jqgrid in middle of grid

前端 未结 1 1303
傲寒
傲寒 2020-12-07 04:59

jqGrid 4.3 allows to add new row using inline edit.

Inline navigator demo in http://trirand.com/blog/jqgrid/jqgrid.html Shows that after add command grid is scrolled

相关标签:
1条回答
  • 2020-12-07 05:28

    In the answer I suggested to extend addRowData method to support new 'afterSelected' and 'beforeSelected' values (additionally to existing 'first', 'last', 'before' and 'after') of the position parameter. I shown one can overwrite (subclass) the original addRowData method to add the support without writing the full code of addRowData.

    In the corresponding demo I demonstrated how one could use the feature in case of the usage of form editing.

    In the same way we can solve the problem in the inlineNav method too. The new demo demonstrate this.

    The corresponding code is practically the copy of the codes from the answer.

    var oldAddRowData = $.fn.jqGrid.addRowData;
    
    $.jgrid.extend({
        addRowData: function (rowid, rdata, pos, src) {
            if (pos === 'afterSelected' || pos === 'beforeSelected') {
                if (typeof src === 'undefined' && this[0].p.selrow !== null) {
                    src = this[0].p.selrow;
                    pos = (pos === "afterSelected") ? 'after' : 'before';
                } else {
                    pos = (pos === "afterSelected") ? 'last' : 'first';
                }
            }
            return oldAddRowData.call(this, rowid, rdata, pos, src);
        }
    });
    
    ...
    $("#list").jqGrid('inlineNav', '#pager', {addParams: {position: "afterSelected"}});
    

    Probably I should post to trirand the corresponding suggestion to modify the original addRowData method with the described above features.

    0 讨论(0)
提交回复
热议问题