2013-05-09 62 views
0

我正在使用jQuery handsontable plugin,我想知道是否有任何方法使用“依赖”列。使用hansontable插件的依赖列

这是,当我更改一列时,另一列将根据以前的列值进行更新。

我的一列是电话location,自动完成显示可能位置的列表。 (城市+邮政编码+国家) 然而,在我的数据库中,我正在为每个位置仅存储一个id。因此,我需要一个隐藏列来存储它(我已经创建了该列),但是当用户使用自动完成更改location列时,我需要它来更新。

这是可能的吗?我没有在文档或互联网上找到任何东西。

谢谢。

回答

0

是的,我做的正是这种出于同样的原因,你

使用改动后的事件作为...

afterChange: function (changes, source) { AfterChange(changes, source); } 

...你可以改变其他单元格的值...

function AfterChange(Changes, Source) { 
    if (Source === 'loadData') { 
     return; //don't do anything on load 
    } 
    var rowIndex = 0, columnID = 1, oldTextVal = 2, newTextVal = 3, ntv = '', nv = ''; 
    $(Changes).each(function() { 
     if (this[columnID] === 'RegionID') { 
      //Make sure nothing else happens when these columns are set through below, to avoid circular references 
     } 
     else if (this[columnID] === 'RegionName') { 
      ntv = this[newTextVal]; 
      //I have a dropdown used for filtering which has the id as value where I get the id from 
      nv = $('#RegionsFilterDropdown option').filter(function() { return $(this).text() === ntv; }).val(); 
      $container.handsontable('setDataAtCell', this[rowIndex], 12, nv); 
     } 
    }); 
} 

我希望这可以帮助...