oTable.columnFilter({
sPlaceHolder: "head:before",
aoColumns: [
{ type: "select", values: myArray},
{ type: "text" },
{ type: "select", values: category }
]
});
我想将数据绑定(bind)到列过滤器的一个下拉列表,为此我需要为下拉列表分配 ID 或名称......我该如何实现? 我在这里使用的是数据表版本 1.9..
最佳答案
使用数据表的属性createdRow,每当数据表中创建任何行时,都会自动创建rowId。 https://datatables.net/reference/option/createdRow对于数据表 1.10+
http://legacy.datatables.net/release-datatables/examples/advanced_init/row_callback.html对于数据表 1.9
"createdRow": function (row, data, rowId) {
var $rowCreated = $(row);
$rowCreated.data('rowData', data).attr('data-row-id', rowId);
//Row Single-Click Event Handler
$rowCreated.on('click', function () {
var $rowClicked = $(this);
var rowData = $rowClicked.data('rowData');
$rowClicked.addClass('selected').siblings().removeClass('selected');
// Do any operation for onClick
});
},
对于数据表 1.9
$('#example').dataTable( {
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
//Here you have iDisplayIndex, the row index
}
})
关于javascript - 如何将id添加到jquery数据表中列过滤器的类型选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45475559/