如何从按钮中删除javascript函数中的行 例如
答案 0 :(得分:16)
如果您使用的是DataView,请使用以下命令:
DataView.deleteItem(RowID);//RowID is the actual ID of the row and not the row number
Grid.invalidate();
Grid.render();
如果您只知道行号,可以使用以下命令获取theRowID:
var item = DataView.getItem(RowNum);//RowNum is the number of the row
var RowID = item.id
答案 1 :(得分:6)
假设您使用的是jQuery
var grid;
$(function () {
// init options, load data
...
var columns = [];
columns[0] = {
id: 'id',
name: '#',
field: 'id', // suppose you have an id column in your data model
formatter: function (r, c, id, def, datactx) {
return '<a href="#" onclick="RemoveClick(' + id + ',' + r + ')">X</a>'; }
}
// init other columns
...
grid = new Slick.Grid($('#gridDiv'), data, columns, options);
}
function RemoveClick(databaseId, gridRow) {
// remove from serverside using databaseId
...
// if removed from serverside, remove from grid using
grid.removeRow(gridRow);
}
答案 2 :(得分:5)
这就是我这样做的方式(不使用任何数据提供者):
//assume that "grid" is your SlickGrid object and "row" is the row to be removed
var data = grid.getData();
data.splice(row, 1);
grid.setData(data);
grid.render();
我在实时项目中使用它并且运行良好。当然,如果你想删除多行,那么应该进行一些调整,或者如果你使用数据提供者,那么你可能只想从数据提供者中删除行,然后让SlickGrid刷新行。 / p>
希望有所帮助:)
答案 3 :(得分:4)
function deleteRows() {
var selectedIndexes = grid.getSelectedRows().sort().reverse();
var result = confirm("Are you sure you want to delete " + grid.getSelectedRows().length + " row(s)?");
if (result) {
$.each(selectedIndexes, function (index, value) {
var item = dataView.getItem(value); //RowNum is the number of the row
if (item)
dataView.deleteItem(item.id); //RowID is the actual ID of the row and not the row number
});
grid.invalidate();
grid.render();
}
}
答案 4 :(得分:1)
var rowsToDelete = grid.getSelectedRows().sort().reverse();
for (var i = 0; i < rowsToDelete.length; i++) {
data.splice(rowsToDelete[i], 1);
}
grid.invalidate();
grid.setSelectedRows([]);
答案 5 :(得分:-2)
是的,当然,我这样用它
var selrow = grid.getSelectedRows ();
data.splice(selrow, 1);
grid.invalidateAllRows();
grid.render ();
问候
答案 6 :(得分:-3)
喜 我用这个脚本删除了SlickGrid的行
function deletefila(numrow) {
alert("delete row"+numrow);
data.splice(numrow,1);
grid.removeAllRows();
grid.render();
//grid.removeRow(5);
//grid.updateRowCount();
//and then invalidate and re-render the grid by calling grid.removeAllRows() followed by grid.render().
}