Skip to content

Commit

Permalink
Edited js/grid.base.js via GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
iliadraznin committed Aug 16, 2011
1 parent 231ecb5 commit acb3bdc
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions js/grid.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2875,29 +2875,41 @@ $.jgrid.extend({
},
remapColumns : function(permutation, updateCells, keepHeader)
{
// check to see there is a reason to remap
var pl = permutation.length, i, remap = false;
for (i = 0; i < pl; i++) {

This comment has been minimized.

Copy link
@iliadraznin

iliadraznin Aug 16, 2011

Author Owner

In some cases, such with columnChooser, remapColumns may be called without actually having a different order for the columns, this check should improve performance significantly in such cases, without impacting much the rest.

if (permutation[i] != i) remap = true;
}

if (!remap) return;

function resortArray(a) {
var ac;
if (a.length) {
ac = $.makeArray(a);
} else {
ac = $.extend({}, a);
var ac = a.length ? $.makeArray(a) : $.extend({}, a);
// replace $.each with for loop
for (i = 0; i < pl; i++) {
a[i] = ac[permutation[i]];
}
$.each(permutation, function(i) {
a[i] = ac[this];
});
}
var ts = this.get(0);
function resortRows(parent, clobj) {
$(">tr"+(clobj||""), parent).each(function() {
var row = this;
var elems = $.makeArray(row.cells);
$.each(permutation, function() {
var e = elems[this];
if (e) {
row.appendChild(e);
var rows = parent.find(">tr" + (clobj || "")),

This comment has been minimized.

Copy link
@iliadraznin

iliadraznin Aug 16, 2011

Author Owner

Lookup via parent.find is a bit faster than by using parent as context

rl = rows.length,
ri,
row,
cells,
cell;

for (ri = 0; ri < rl; ri++) {
row = rows[ri];
cells = $.makeArray(row.cells);

for (i = 0; i < pl; i++) {
cell = cells[permutation[i]];
if (cell) {
row.appendChild(cell);
}
});
});
}
}
}
resortArray(ts.p.colModel);
resortArray(ts.p.colNames);
Expand Down

1 comment on commit acb3bdc

@iliadraznin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance improvements for remapColumns

Please sign in to comment.