1

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/

Andrus
  • 26,339
  • 60
  • 204
  • 378

1 Answers1

3

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • According to Tony reply in trirand forum it seems that those are already implemented in jqGrid. Which is best way to force added row to appear before current row in inline and form add modes ? – Andrus Dec 15 '11 at 10:47
  • 1
    @Andrus: Please look at [my answer](http://www.trirand.com/blog/?page_id=393/feature-request/force-added-row-in-inline-edit-to-appear-before-current-row/#p25427) to the post of Tony. – Oleg Dec 15 '11 at 10:57
  • Oleg. Thank you very much. Context menu from toolbar you created shows inline navigator buttons as active if they are not active in jqgrid toolbar. How to fix this ? – Andrus Dec 15 '11 at 19:23
  • 1
    @Andrus: I think one should just include additional test whether the toolbar button has `'ui-state-disabled'` class or not. I think your question is not about the problem discussed in the question/the answer. It's the subject of the [answer](http://stackoverflow.com/a/8491939/315935) and I will answer you therein. – Oleg Dec 15 '11 at 21:31
  • @Oleg: can you look at this one, it is an extension of this question - http://stackoverflow.com/questions/9238092/jqgrid-extending-addrowdata – techlead Feb 11 '12 at 05:33
  • @Oleg : In 4.8.0 this causes exception `Cannot read property 'addRowData' of undefined` . Is this fix already included or how to fix ? – Andrus Mar 09 '15 at 11:32
  • @Andrus: I tried the above code with free jqGrid 4.8 and I could not see any problem. I used of cause new option `inlineEditing: {position: "afterSelected"}` to specify `position` (see [here](https://github.com/free-jqgrid/jqGrid/wiki/New-style-of-usage-options-of-internal-methods#solution-of-the-problem-in-free-jqgrid-48)). Are you sure that the row is selected? Could you verify your code and open new question with the demo example if the problem will not solved? I will include the feature with `afterSelected` in the main code of free jqGrid. I forgot just about the feature. – Oleg Mar 09 '15 at 12:36
  • @Andrus: I posted additional details in [the issue](https://github.com/free-jqgrid/jqGrid/issues/19) which you posted. – Oleg Mar 09 '15 at 13:23
  • 1
    @user3850805: Thank you! By the way, [free jqGrid](https://github.com/free-jqgrid/jqGrid), my fork of jqGrid, includes the option "afterSelected" of `addRowData`. Thus one don't need to "subclass" `addRowData` if one use free jqGrid. – Oleg Dec 03 '15 at 06:03