我试图弄清楚如何结合Slickgrid的示例4和示例9.基本上将行重新排序添加到数据视图网格。到目前为止,只要网格中只有一个页面,我就会进行行重新排序。对于多个页面,行重新排序仅适用于第一页和任何其他页面,行可以向上或向下拖动,但不会重新排序。
示例4:https://github.com/mleibman/SlickGrid/blob/master/examples/example4-model.html
示例9:https://github.com/mleibman/SlickGrid/blob/master/examples/example9-row-reordering.html
有什么想法吗?非常感谢!
以下是我在数据视图网格上的行重新排序代码:
//Re-order rows on drag
var moveRowsPlugin = new Slick.RowMoveManager({});
moveRowsPlugin.onBeforeMoveRows.subscribe(function (e, inboxData) {
for (var i = 0; i < inboxData.rows.length; i++) {
// no point in moving before or after itself
if (inboxData.rows[i] == inboxData.insertBefore || inboxData.rows[i] == inboxData.insertBefore - 1) {
e.stopPropagation();
return false;
}
}
return true;
});
moveRowsPlugin.onMoveRows.subscribe(function (e, args) {
var extractedRows = [], left, right;
var rows = args.rows;
var insertBefore = args.insertBefore;
left = inboxData.slice(0, insertBefore);
right = inboxData.slice(insertBefore, inboxData.length);
rows.sort(function(a,b) { return a-b; });
for (var i = 0; i < rows.length; i++) {
extractedRows.push(inboxData[rows[i]]);
}
rows.reverse();
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (row < insertBefore) {
left.splice(row, 1);
} else {
right.splice(row - insertBefore, 1);
}
}
inboxData = left.concat(extractedRows.concat(right));
var selectedRows = [];
for (var i = 0; i < rows.length; i++)
selectedRows.push(left.length + i);
inboxGrid.resetActiveCell();
inboxDataView.setItems(inboxData);
inboxGrid.setSelectedRows(selectedRows);
inboxGrid.render();
});
inboxGrid.registerPlugin(moveRowsPlugin);
//End re-order rows
答案 0 :(得分:0)
我不确定,但也许这些方法可以帮到你:
inboxGrid.invalidateAllRows(); //tells the grid that all the rows has been changed and it needs to rerender them.
inboxGrid.invalidateRows(rows); // tells the grid that the specified rows has been changed and it needs to rerender them.
更新dataView时还需要使用beginUpdate和endUpdate:
inboxDataView.beginUpdate();
inboxDataView.setItems(inboxData);
inboxDataView.endUpdate();
希望这些帮助。