我有两个网格,允许用户在它们之间复制行。对于小型数据集,没问题,但对于大型数据集(5-10000),我注意到 JQGrid 非常慢。这就是我现在所拥有的:
$('#imgRightArrow').click(function ()
{
var fromGrid = $('#fromGrid');
var toGrid = $('#toGrid');
var rowKeys = fromGrid.getGridParam('selarrrow');
var j = rowKeys.length - 1;
if (j >= 0) $('body').addClass('loading');
(function ()
{
for (; j >= 0; j--) // - high to low to avoid id reordering
{
var row = fromGrid.jqGrid('getRowData', rowKeys[j]);
toGrid.addRowData('gtp_' + rowKeys[j], row); // - add prefix to keep rowid's unique between grids
fromGrid.delRowData(rowKeys[j]);
if (j % 100 === 0)
{
$('#fromGridHeader').text(fromGrid.jqGrid('getGridParam', 'records') + ' Cards on this Order');
$('#toGridHeader').text(toGrid.jqGrid('getGridParam', 'records') + ' Cards to be Dispatched');
if (j === 0) // - done
$('body').removeClass('loading');
else
{
j--;
window.setTimeout(arguments.callee); // - set a timer for the next iteration
break;
}
}
}
})();
});
它太慢了,我不得不使用 kludge 来防止浏览器超时。
我试过这样的事情:
$('#imgRightArrow').click(function ()
{
var fromGrid = $('#fromGrid');
var toGrid = $('#toGrid');
var copyData = toGrid.jqGrid('getRowData'); // - existing data
var rowKeys = fromGrid.getGridParam('selarrrow');
var j = rowKeys.length - 1;
if (j >= 0) $('body').addClass('loading');
(function ()
{
for (; j >= 0; j--)
{
copyData.push(fromGrid.jqGrid('getRowData', rowKeys[j]));
fromGrid.jqGrid('delRowData', rowKeys[j]);
if (j % 100 === 0)
{
if (j === 0)
{
fromGrid[0].refreshIndex();
toGrid.jqGrid('clearGridData', true);
toGrid.setGridParam({ data: copyData });
toGrid[0].refreshIndex();
toGrid.trigger('reloadGrid');
$('#fromGridHeader').text(fromGrid.jqGrid('getGridParam', 'records') + ' Cards on this Order');
$('#toGridHeader').text(toGrid.jqGrid('getGridParam', 'records') + ' Cards to be Dispatched');
$('body').removeClass('loading');
}
else
{
j--; // - manually decrement since we break
window.setTimeout(arguments.callee); // - set a timer for the next iteration
break;
}
}
}
})();
});
...似乎更快,但从 fromGrid 中删除行仍然使用 delRowData,这非常慢。
关于如何有效地为大型数据集完成此任务的任何想法?