javascript Handsontable - getSelected 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17386258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 08:07:40  来源:igfitidea点击:

Handsontable - getSelected not working

javascriptexcelgetselectionhandsontable

提问by user2535621

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:

我正在使用 handsontable 创建一些类似 excel 的电子表格,我需要检索用户选择的数据以使用 gRaphael 创建图表。但是当我尝试使用以下代码提醒数据选择参数时:

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?

我在警报窗口中写了“未定义”。有人可以告诉我如何修复此代码吗?

回答by PostureOfLearning

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:

您的代码已过时,这可能是它无法按预期工作的原因。如果您使用的是最新版本 0.9.7,推荐的方法是:

$('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:

正如@polras 所建议的,您还可以添加:

outsideClickDeselects: false 

to handsonetable options

到handsonable选项