顺便说一下,我正在使用Tabulator,这是一个了不起的工具,但遇到了麻烦。我想在所有行中放置一个HTML Select,并为每个记录提供选项。当我更改选择选项时,我调用一个函数,并且正在接收单元格数据(使用cell.getData()
)。但是,我如何也获得选择选项的值呢?
我所拥有的:
var selectHTML = function() {
return '<select class="custom-select" id="select1" name="select1"><option value="0">Select</option><option value="1">Option 1</option><option value="2">Option 2</option></select>';};
var table = new Tabulator("#example-table", {
langs: {
"es-es": {
"pagination": {
"first":"Primer página",
"first_title":"Primer página",
"last":"Última página",
"last_title":"Última página",
"prev":"Anterior",
"prev_title":"Anterior",
"next":"Siguiente",
"next_title":"Siguiente",
"page_size":"Resultados a mostrar"
},
"ajax":{
"loading":"Cargando",
"error":"Error"
},
},
},
height:"500",
layout:"fitColumns",
placeholder:"Sin datos",
responsiveLayout:true,
pagination:"local",
paginationSize:10,
paginationSizeSelector:[3, 6, 8, 10, 50],
movableColumns:true,
columns:[
{title:"Zipcode", field:"zipcode", sorter:"number"},
{title:"Productor", field:"nombre", sorter:"string"},
{title:"Action", formatter:selectHTML, cellClick:function(e, cell){
var element = cell.getElement().children.select1.value;
test(element, cell.getData());
}},
{title:"", formatter:editIcon, align:"center", cellClick:function(e, cell) {
var data = cell.getData();
modificar_nombre(data);
}},
],
locale:"es-es"
});
function test(selectedOption, data) {
if(selectedOption != 0) {
alert("Chosed option: " + selectedOption);
}
}
期待任何答复。非常感谢!
答案 0 :(得分:0)
好吧,我这样解决了我的问题:
var element= cell.getElement().children.select1.value;
test(element, cell.getData());
* test是函数的名称
Buuuut ...问题在于,只要单击单元格,就可以执行test()
{title:"Action", formatter:selectHTML, cellClick:function(e, cell) {
var element = cell.getElement().children.select1.value;
test(element, cell.getData());
}},
如果选择选项更改,我只想执行它...
所以我将等待任何回复。干杯!