Handsontable - getSelected not working

user2535621 picture user2535621 · Jun 30, 2013 · Viewed 11.2k times · Source

I'm using handsontable to create some excel-like spreadsheets and I need to retrieve the data selected by the user to create a chart using gRaphael. But when I try to even alert the data selection parameters using this code:

var ht = $('#dataTable0').data('handsontable');
var sel = ht.getSelected();
alert(sel[0]);

I get 'undefined' written in the alert window. Can someone tell me how to fix this code?

Answer

PostureOfLearning picture PostureOfLearning · Jun 30, 2013

Your code is obsolete, which may be the reason it doesn't work as intended. The recommended way if you are using the latest version 0.9.7 is:

$('div#example1').handsontable(options);

//get the instance using jQuery wrapper
var ht = $('#example1').handsontable('getInstance');

//Return index of the currently selected cells as an array [startRow, startCol, endRow, endCol]
var sel = ht.getSelected();

//'alert' the index of the starting row of the selection
alert(sel[0]);

If you are using an older version I suggest downloading the latest version.

EDIT:

As suggested by @polras, you can also add:

outsideClickDeselects: false 

to handsonetable options