我正在为表使用 jquery 数据表插件。我想对我选择的列中的每个值执行检查。我该怎么做?
我已经试过了,但它会检查数据表中存在的所有值。有没有办法针对特定列中的值而不是整个数据表值执行此操作?
这是 HTML
<table id="example">
<thead>
<tr>
<th>id</th>
<th>Currency</th>
<th>Lots</th>
</tr>
</thead>
</table>
这是 Javascript
var table = $('#example').DataTable({
"bPaginate": false,
"bInfo" : false,
"columns": [
{"data": "id"},
{"data": "currency"},
{"data": "lots"}
]
});
table.cells().every( function () {
if ( this.data() > 5000 ) {
$(this.node()).addClass( 'warning' );
}
} );
我希望 lots 列中大于 5000 的所有值都具有“警告”类。
最佳答案
我认为您可以使用 column().nodes(),如文档中所述:
https://datatables.net/reference/api/column().nodes()
table.column(1).nodes().each( function () {
if ( this.data() > 5000 ) {
$(this.node()).addClass( 'warning' );
}
} );
关于javascript - 如何检查 jQuery 数据表中特定列的每个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57658047/