aoColumnDefs: [ { "bVisible": true, "aTargets": [0] }, { "bVisible": true, "aTargets": [1] }, { "bVisible": true, "aTargets": [2] }, { "bVisible": true, "aTargets": [3] }, { "bVisible": true, "aTargets": [4] }, { "bVisible": true, "aTargets": [5] }, { "bVisible": true, "aTargets": [6] }, { "bVisible": true, "aTargets": [7] }, { "bVisible": true, "aTargets": [8] }, { "bVisible": true, "aTargets": [9] }, { "bVisible": true, "aTargets": [10] } ]为它的第10个目标位置加一个如果值为0,bVisible为不可见
时间: 2023-12-10 14:42:06 浏览: 119
你可以这样修改代码:
```
aoColumnDefs: [
{ "bVisible": true, "aTargets": [0] },
{ "bVisible": true, "aTargets": [1] },
{ "bVisible": true, "aTargets": [2] },
{ "bVisible": true, "aTargets": [3] },
{ "bVisible": true, "aTargets": [4] },
{ "bVisible": true, "aTargets": [5] },
{ "bVisible": true, "aTargets": [6] },
{ "bVisible": true, "aTargets": [7] },
{ "bVisible": true, "aTargets": [8] },
{ "bVisible": function(data, type, row, meta) {
return (meta.col == 9 && data == 0) ? false : true;
}, "aTargets": [9] },
{ "bVisible": true, "aTargets": [10] }
]
```
这里使用了一个函数来判断第10个目标位置的可见性。如果该单元格数据为0,则返回false,否则返回true,从而控制其可见性。
相关问题
aoColumnDefs: [ { "bVisible": true, "aTargets": [0] }, { "bVisible": true, "aTargets": [1] }, { "bVisible": true, "aTargets": [2] }, { "bVisible": true, "aTargets": [3] }, { "bVisible": true, "aTargets": [4] }, { "bVisible": true, "aTargets": [5] }, { "bVisible": true, "aTargets": [6] }, { "bVisible": true, "aTargets": [7] }, { "bVisible": true, "aTargets": [8] }, { "bVisible": true, "aTargets": [9] }, { "bVisible": true, "aTargets": [10] } ]当第十列单元格为0的时候不显示
您可以在第十列的配置中添加一个条件,来控制当单元格为0时不显示。修改后的代码如下:
```
aoColumnDefs: [
{ "bVisible": true, "aTargets": [0] },
{ "bVisible": true, "aTargets": [1] },
{ "bVisible": true, "aTargets": [2] },
{ "bVisible": true, "aTargets": [3] },
{ "bVisible": true, "aTargets": [4] },
{ "bVisible": true, "aTargets": [5] },
{ "bVisible": true, "aTargets": [6] },
{ "bVisible": true, "aTargets": [7] },
{ "bVisible": true, "aTargets": [8] },
{
"bVisible": function ( data, type, row ) {
return row[9] !== 0;
},
"aTargets": [9]
},
{ "bVisible": true, "aTargets": [10] }
]
```
在第十列的配置中,我们使用了一个函数作为 `bVisible` 的值,这个函数会在每个单元格被渲染时执行。函数接收三个参数:
- `data`:当前单元格的数据。
- `type`:当前单元格的类型,可能的值为 `display`(在表格中显示的数据)和 `filter`(在过滤器中使用的数据)。
- `row`:当前行的数据。
我们在函数中判断了当前单元格的值是否为0,如果是,则返回 `false`,表示不显示该单元格。否则返回 `true`,表示显示该单元格。
$.plat.main.datatable({ id: 'tb_Table', sAjaxSource: "/CKReport/PageListStockReport?CangkuId=" + $("#CangkuId").val() + "&stime=" + $("#stime").val() + "&etime=" + $("#etime").val() + "&mtypeId=" + $("#mtypeId").val() + "&materielName=" + $("#materielName").val(), aoColumnDefs: [ { "bVisible": true, "aTargets": [0] }, { "bVisible": true, "aTargets": [1] }, { "bVisible": true, "aTargets": [2] }, { "bVisible": true, "aTargets": [3] }, { "bVisible": true, "aTargets": [4] }, { "bVisible": true, "aTargets": [5] }, { "bVisible": true, "aTargets": [6] }, { "bVisible": true, "aTargets": [7] }, { "bVisible": true, "aTargets": [8] }, { "bVisible": true, "aTargets": [9] }, { "bVisible": true, "aTargets": [10] } ] });当第十列单元格为0的时候不显示
您可以通过在 `aoColumnDefs` 中的第 10 列中添加一个 `fnCreatedCell` 回调函数来实现此目的。在该函数中,您可以检查单元格的值是否为 0,如果是,则将单元格的 `display` 属性设置为 `none`,将其隐藏。以下是实现此目的的代码示例:
```
$.plat.main.datatable({
id: 'tb_Table',
sAjaxSource: "/CKReport/PageListStockReport?CangkuId=" + $("#CangkuId").val()
+ "&stime=" + $("#stime").val() + "&etime=" + $("#etime").val()
+ "&mtypeId=" + $("#mtypeId").val() + "&materielName=" + $("#materielName").val(),
aoColumnDefs: [
{ "bVisible": true, "aTargets": [0] },
{ "bVisible": true, "aTargets": [1] },
{ "bVisible": true, "aTargets": [2] },
{ "bVisible": true, "aTargets": [3] },
{ "bVisible": true, "aTargets": [4] },
{ "bVisible": true, "aTargets": [5] },
{ "bVisible": true, "aTargets": [6] },
{ "bVisible": true, "aTargets": [7] },
{ "bVisible": true, "aTargets": [8] },
{
"bVisible": true,
"aTargets": [9],
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
if (sData === "0") {
$(nTd).css("display", "none");
}
}
},
{ "bVisible": true, "aTargets": [10] }
]
});
```
在上面的代码中,我们将第 10 列的 `fnCreatedCell` 回调函数定义为一个匿名函数。该函数的参数包括单元格的 DOM 元素 `nTd`、单元格的数据 `sData`、行数据对象 `oData`、行索引 `iRow` 和列索引 `iCol`。我们在该函数中检查单元格的值是否为 0,如果是,则使用 jQuery 的 `css` 方法将单元格的 `display` 属性设置为 `none`,将其隐藏。
阅读全文