我正在使用dataTables,我想在满足特定要求时将th的字体颜色更改为红色,但它不起作用。 这显示一列的总和。数据通过DataTables api动态插入ajax。
如果我更改了要执行.css的元素("颜色","红色"),只要它在表格之外就可以正常工作。
jquery的
desna = $('#skupina').DataTable({
"paging": false,
"scrollY": "700px",
"scrollCollapse": true,
//stateSave: true,
bInfo: false,
"columnDefs": [
{
"targets": [ 1 ],
"visible": false,
"searchable": false
}],
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 : typeof i === 'number' ? i : 0;
};
// Total over all pages
total = api
.column( 3 )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Total over this page
pageTotal = api
.column( 3, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column( 3 ).footer() ).html(
pageTotal +' kg'
);
}
});
$('#druga').on("change", "#vozilo", function () {
var g = $('#grupa').val();
max_kg = parseInt($(this).children(":selected").attr("id"));
if(max_kg<pageTotal){
alert("nope");
$("#foto").css( "color", "red" );
};
});
PHP
function zaglavlje($row, $rbr) {
echo '<thead>';
echo '<tr>
<th>Adresa</th>
<th>Grad</th>
<th>Drzava</th>
<th><input type="checkbox" id="all'.$rbr.'" align="center"/></th>
</tr>
<tfoot>
<tr>
<th colspan="10" id="foto" contenteditable="true"></th>
</tr>
</tfoot>';
echo '</thead>';
}
答案 0 :(得分:0)
我给了这个类,当我在那个类上调用.css()时,它就有效了。
答案 1 :(得分:0)
我认为你在寻找
$('#example').dataTable( {
"drawCallback": function( settings ) {
$('#example tr:eq(0) th:eq(0)').text("Text update by code");
}
} );
相同如果您想使用DataTable设置列,请click Here