Rich T.
Rich T.

Reputation: 110

JQGrid refreshIndex() method for local data not clearing previous index array

I have local data delete functionality:

$.each(rowids, function() {  // - delete selected rows
                $grid.delRowData(this);
            });

I noticed that after this call, doing retrieving the _index:

var xref = $grid.jqGrid('getGridParam', '_index');

the _index still contains the deleted row.

I looked into the JQGrid source, after the deletion of the local data, a call to refreshIndex() is made. I noticed that the Index is not removed, but rather the existing array is overwritten:

for (i = 0; i < datalen; i++) {
            val = $.jgrid.getAccessor(ts.p.data[i], idname);
            if (val === undefined) { val = String(i + 1); }
            ts.p._index[val] = i;
        }

I added the following right before the loop above:

ts.p._index = [];

This appears to resolve my issue, will this cause problems?

Upvotes: 1

Views: 557

Answers (1)

Oleg
Oleg

Reputation: 221997

I think that you are right. One could change the line of delRowData to

delete $t.p._index[id];

and one should add the line

ts.p._index = [];

before the loop exactly like you suggested.

I think you should post the corresponding bug report to trirand.

Upvotes: 1

Related Questions