来自列 属性 的可操作下拉源
Handsontable dropdown source from column property
找不到解决方案,也许有人会提供帮助。
我有一组类似这样的数据:
[
{
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: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white']
}
]
但我需要这个:
columns: [
{
type: 'dropdown',
source: 'chassis_color' // it should understand that this property is an array and populate source with it
}
]
以同样的方式工作。
我需要这个,因为我有非常大的数据集,很难手动设置。
谢谢。
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 中的完整示例。
找不到解决方案,也许有人会提供帮助。
我有一组类似这样的数据:
[
{
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: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white']
}
]
但我需要这个:
columns: [
{
type: 'dropdown',
source: 'chassis_color' // it should understand that this property is an array and populate source with it
}
]
以同样的方式工作。
我需要这个,因为我有非常大的数据集,很难手动设置。
谢谢。
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 中的完整示例。