DataTables 的自动填充扩展 - 列禁用不起作用
DataTables' Autofill extension - column disabling not working
我正在使用带有自动填充扩展的 Datatables 插件,输入元素如下所述:
。
这很好用。但是,我无法禁用特定列的自动填充。当我使用 "enable": false 选项并将其设置为特定列时,回调将停止工作。有谁知道是否有办法禁用某些列进行自动填充,同时仍允许回调正常运行?以下禁用列 1-4,但 read/write/step 函数不再复制编辑的输入值:
new $.fn.dataTable.AutoFill(table, {
"columnDefs": [{
"targets": [5, 6, 7, 8, 9],
"read": function (cell) {
return $('input', cell).val();
},
"write": function (cell, val) {
return $('input', cell).val(val);
},
"step": function (cell, read, last, i, x, y) {
return last === undefined ? read : last;
},
"enable": false, "targets": [1,2,3,4] //omitting this leaves all columns enabled.
}]
});
按照您编写的方式,您在同一个对象中定义了两次 targets
属性。你需要做的是给 columnDefs
另一个指向其他目标的对象。像这样:
new $.fn.dataTable.AutoFill(table, {
columnDefs: [
{
targets: [5, 6, 7, 8, 9],
read: function (cell) {
return $('input', cell).val();
},
write: function (cell, val) {
return $('input', cell).val(val);
},
step: function (cell, read, last, i, x, y) {
return last === undefined ? read : last;
}
},
{
targets: [1,2,3,4],
enable: false
}
]
});
我正在使用带有自动填充扩展的 Datatables 插件,输入元素如下所述:
new $.fn.dataTable.AutoFill(table, {
"columnDefs": [{
"targets": [5, 6, 7, 8, 9],
"read": function (cell) {
return $('input', cell).val();
},
"write": function (cell, val) {
return $('input', cell).val(val);
},
"step": function (cell, read, last, i, x, y) {
return last === undefined ? read : last;
},
"enable": false, "targets": [1,2,3,4] //omitting this leaves all columns enabled.
}]
});
按照您编写的方式,您在同一个对象中定义了两次 targets
属性。你需要做的是给 columnDefs
另一个指向其他目标的对象。像这样:
new $.fn.dataTable.AutoFill(table, {
columnDefs: [
{
targets: [5, 6, 7, 8, 9],
read: function (cell) {
return $('input', cell).val();
},
write: function (cell, val) {
return $('input', cell).val(val);
},
step: function (cell, read, last, i, x, y) {
return last === undefined ? read : last;
}
},
{
targets: [1,2,3,4],
enable: false
}
]
});