Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

how to add new row in jqgrid in middle of grid

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 to top and added row appears in top of grid. This is confusing.

How to force added row to appear before current row?

I posted this as feature request in http://www.trirand.com/blog/?page_id=393/feature-request/force-added-row-in-inline-edit-to-appear-before-current-row/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...