Not able to delete rows using HandsOnTable

automaticAllDramatic picture automaticAllDramatic · Jul 4, 2013 · Viewed 11.2k times · Source

I am not able to remove rows with the latest version. I am using version 0.9.9.

This is what I do:

var $container = $("#add-table");
$container.handsontable(options);

var handsontable = $container.data('handsontable');
var data = handsontable.getData();
if(data.length > 1 && handsontable.isEmptyRow(data.length-1)) {
    handsontable.alter('remove_row', parseInt(data.length-1));
}

There was a similar question on Handsontable delete multiple rows but that does not solve my purpose. The fiddle on this link does not work with the solution provided.

Any help would be appreciated.

Answer

Kiran Ruth R picture Kiran Ruth R · Jul 10, 2013

So i am guessing you want to delete an empty last row ?

Make sure you have not set minSpareRows to a value more than 0(default) . If the minSpareRows is more than zero u cannot delete the extra row using alter('remove_row').

i used this data to simulate the empty last row :

var myData = [
    ["", "Kia", "Nissan", "Toyota", "Honda"],
    ["2008", 10, 11, 12, 13],
    ["2009", 20, 11, 14, 13],
    ["2010", 30, 15, 12, 13],
    ["",,,]
];

Checkout the example .When u click on del link it deletes the empty last row . Hope this helps you

Working Example