当前标准的,getSelected()
回报什么...
getSelected: function() {
//https://github.com/warpech/jquery-handsontable/issues/44
//cjl if (selection.isSelected()) {
//return [priv.selStart.row(), priv.selStart.col(), priv.selEnd.row(), priv.selEnd.col()];
//}
}
这是一个巨大的问题,因为handsontable引用功能相当多。但是,幸运的是,我们可以使用afterSelectionEnd event。被选择(在鼠标弹起)一个或多个小区之后
afterSelectionEnd (r: Number, c: Number, r2: Number, c2: Number)
回调烧制。
参数:
r
选择开始行
c
选择起始列
r2
选择结束行
c2
选择结束列
按照API,
alter ('remove_row', index: Number, amount: Number (Optional), source: String (Optional))
删除给定索引处的行。默认金额等于1
这意味着要使用alter('remove_row')
,我们只需要提供索引。
这是我做的一个working demo以获得理想的结果。
注:
由于一个bug,我们需要添加一些逻辑在afterSelectionEnd event
。
JAVASCRIPT:
var myData = [
["", "Kia", "Nissan", "Toyota", "Honda"],
["2008", 10, 11, 12, 13],
["2009", 20, 11, 14, 13],
["2010", 30, 15, 12, 13]
];
//declare row vars
var row1 = null,
row2 = null;
var $container = $("#exampleGrid");
$container.handsontable({
data: myData,
startRows: 5,
startCols: 5,
minSpareCols: 0,
minSpareRows: 0,
rowHeaders: true,
colHeaders: true,
contextMenu: true,
afterSelectionEnd: function(x1, y1, x2, y2){
//add this because of bug
if((x1 <= x2 && y1 < y2) || (x1 < x2 && y1 <= y2) || (x1 == x2 && y1 == y2)) {
row1 = x1;
if(x1 == 0)
row2 = parseInt(x2 + 1);
else
row2 = x2;
}
else if((x1 >= x2 && y1 > y2) || (x1 > x2 && y1 >= y2)) {
row1 = x2;
if(x2 == 0)
row2 = parseInt(x1 + 1);
else
row2 = x1;
}
else if(x1 < x2 && y1 > y2) {
row1 = x1;
row2 = x2;
}
else if(x1 > x2 && y1 < y2) {
row1 = x2;
row2 = x1;
}
}
});
//gets instance of handsontable
var instance = $container.handsontable('getInstance');
$('#delete').click(function(){
if(row1 != null){
if(row2 != null || row2 != row1){
instance.alter('remove_row', row1, row2);
}
else{
instance.alter('remove_row', row1);
}
row1 = null;
row2 = null;
}else{
alert('Please select a cell...');
}
});
希望这有助于让我知道,如果你有什么事!
你可以举一个你的表包含的例子吗? – Romoku
它是一个没有数据的空表 – rizwaniqbal
然后你实际上并没有删除任何行。如果您不想显示额外的行和列,请在handsontable选项中设置“minSpareRows:0”和“minSpareCols:0”。 – Romoku