Allo stato attuale, getSelected()
restituisce niente ...
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()];
//}
}
che è un problema enorme in quanto handsontable riferimenti che funzionano un po '. Tuttavia, per fortuna possiamo usare lo afterSelectionEnd event.
afterSelectionEnd (r: Number, c: Number, r2: Number, c2: Number)
richiamata licenziato dopo una o più celle sono selezionate (su mouse in alto).
Parametri:
r
riga iniziale selezione
c
colonna iniziale selezione
r2
fila fine selezione
c2
selezione colonna finale
Secondo la API,
alter ('remove_row', index: Number, amount: Number (Optional), source: String (Optional))
Rimuovi la/e riga/e all'indice indicato. L'importo predefinito è uguale a 1
Ciò significa che per utilizzare alter('remove_row')
, è necessario fornire solo l'indice.
Ecco un working demo che ho fatto per ottenere il risultato desiderato.
NOTA:
A causa di un bug, abbiamo bisogno di aggiungere un po 'di logica nel 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...');
}
});
Spero che questo aiuti e fatemi sapere se avete bisogno di qualsiasi altra cosa!
Puoi dare un esempio di cosa contiene la tua tabella? – Romoku
È una tabella vuota senza dati – rizwaniqbal
Quindi non stai effettivamente rimuovendo alcuna riga. Impostare 'minSpareRows: 0' e' minSpareCols: 0' nelle opzioni handsontable se non si desidera visualizzare le righe e le colonne supplementari. – Romoku