2013-05-09 1 views
0

jQuery handsontable plugin을 사용하고 있으며 "종속"열을 사용할 방법이 있는지 궁금합니다.hansontable plugin을 사용하는 종속 열

하나의 열을 변경하면 다른 열은 이전 열 값에 따라 업데이트됩니다.

내 열 중 하나는 location이며, 자동 완성은 가능한 위치 목록을 보여줍니다. (도시 + 우편 번호 + 국가) 맞습니다. 그러나 데이터베이스에서 각 위치에 대해서만 id 만 저장하고 있습니다. 그러므로 이미 저장 한 숨겨진 열이 필요하지만 사용자가 location 열을 자동 완성을 사용하여 변경할 때 업데이트해야합니다.

는 것을 어떻게 든 수 있습니까? 나는 문서 나 인터넷에서 아무것도 찾지 못했습니다.

감사합니다.

답변

0

예, 나는 ... 당신

가 afterChange 이벤트를 사용하는 것과 같은 이유로 정확히 이런 짓을했는지

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); 
     } 
    }); 
} 

이 정보가 도움이되기를 바랍니다.