2016-11-18 65 views
0

解決策が見つからないので、多分誰かが助けます。列のプロパティからのHandsontableドロップダウンソース

私はこれに類似したデータのセットを持っている:

[ 
     { 
     id: 1, 
     name: 'Nissan', 
     year: 2012, 
     chassis_color: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white'] 
     }, 
     { 
     id: 2, 
     name: 'Chrysler', 
     year: 2014, 
     chassis_color: ['red', 'orange', 'blue', 'gray', 'black', 'white'] 
     }, 
     { 
     id: 3, 
     name: 'Volvo', 
     year: 2015, 
     chassis_color: ['white', 'orange', 'blue', 'red'] 
     } 
    ] 

だから私はありません手動で配列の値を入力することによって、それの値からchassis_color列のドロップダウンを移入する方法を見つけ出すことはできません。ドキュメントの

例:

columns: [ 
      { 
      type: 'dropdown', 
      source: 'chassis_color' // it should understand that this property is an array and populate source with it 
      } 
] 

同じように動作するように:

columns: [ 
     { 
     type: 'dropdown', 
     source: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white'] 
     } 
] 

は、しかし、私はこれが必要です。

私は非常に大きなデータセットを持っており、手動で何かを設定するのは難しいので、これが必要です。

ありがとうございました。

答えて

1

Handsontableは配列としてデータを表示しようとしています。

あなたはソース値を変更するには、セルのプロパティを使用することができます。

cells: function(row, col, prop) { 
    var cellProperties = this; 

    if (col == 0) { 
     cellProperties.type = 'dropdown'; 
     var val = data[row].chassis_color_source; 

     if (typeof val != 'undefined') { 
      cellProperties.source = val; 
     } 
    } 

    return cellProperties; 
} 

全例がこのJSFiddleに。

+0

あなたは私の日を救った。ありがとうございました! – user2960708

関連する問題