在slickgrid中如何从javascript函数中删除一行

ger*_*rar 5 row slickgrid

例如,如何从按钮中删除javascript函数中的行

Bob*_*Bob 16

如果您使用的是DataView,请使用以下命令:

DataView.deleteItem(RowID);//RowID is the actual ID of the row and not the row number
Grid.invalidate();
Grid.render();
Run Code Online (Sandbox Code Playgroud)

如果您只知道行号,则可以使用以下命令获取RowID:

var item = DataView.getItem(RowNum);//RowNum is the number of the row
var RowID = item.id
Run Code Online (Sandbox Code Playgroud)


m0s*_*0sa 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);
}
Run Code Online (Sandbox Code Playgroud)


Teo*_*ndu 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();
Run Code Online (Sandbox Code Playgroud)

我在一个实时项目中使用它,它运行良好.当然,如果要删除多行,那么应该进行一些调整,或者如果使用数据提供程序,那么您可能只想从数据提供程序中删除该行,然后让SlickGrid刷新行.

希望能帮助到你 :)