1 回答
TA贡献1821条经验 获得超6个赞
您可以添加回调以在 php 或 javascript 中进行格式化。
后端解决方案:
$columns = array(
array( 'db' => 'fortunateID', 'dt' => 0 ),
array( 'db' => 'name', 'dt' => 1 ),
array( 'db' => 'title', 'dt' => 2 ),
array( 'db' => 'company', 'dt' => 3 ),
array( 'db' => 'compensation2019', 'dt' => 4 ),
array( 'db' => 'median-employee-pay',
'dt' => 5,
'formatter' => function( $d, $row ) {
return '$ '. number_format($number, 2);
} ),
array( 'db' => 'type-of-position', 'dt' => 6 ),
array( 'db' => 'stock-price-change-2018-19', 'dt' => 7 ),
array( 'db' => 'compensation2018', 'dt' => 8 ),
array( 'db' => 'compensation-increase', 'dt' => 9 )
);
或者您可以在前端进行格式化:
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "php/getTables.php"
"columnDefs" : [
{
"targets": [3,4,6,7,8] //currency columns (0 indexed)
"render": function ( data, type, row, meta ) {
let num = parseInt(data); //cast to number
let formatted = Number(num.toFixed(1)).toLocaleString();
return '$ ' + formatted;
}
}
]
} );
- 1 回答
- 0 关注
- 126 浏览
添加回答
举报