提问者:小点点

动态设置下拉单元格的数据


嗨,这是我使用Handontable的开始,我正在尝试实现一个功能,其中单元格的下拉值取决于另一个单元格的值。在单元格1的更改事件中,我想将新的数据源加载到第2行,这是一个下拉单元格。

当用户在酒店单元格中选择值时,将进行 ajax 调用以查找房间类型。我希望房间类型在更改的酒店字段旁边的房间类型单元格中可用。

请帮帮我。非常感谢。


共1个答案

匿名用户


然后你可以使用setCellMeta更新单元格号2的数据源。
最后,看看带有ajax源代码的自动完成,因为下拉是基于自动完成的,所以它的工作方式是一样的。

您的代码将如下所示:

var myTable = new Handsontable($(...), {
    ...,
    afterChange: function (change, source) {
        //choose the source you want to trigger, accordingly to the doc
        if((source == 'edit' || source == 'autofill' || source == 'paste'))
        {
            /*if you have multiples lines in your handsontable, then 
              the change array has one line per line in your table */
            for(var i = 0 ; i < change.length ; i++) {
                // I suppose here cell 2 is in row 2 (second argument)
                myTable.setCellMeta(
                     change[i][0],
                     2,
                     'source',
                     function(query,process) {
                         $.ajax({...})
                     }
                 )
            }
        }