$(document).ready(function() {
$('#myTable').DataTable({
"language": { //把提示信息中文化
"lengthMenu": "显示 _MENU_ 条每页",
"zeroRecords": "没有记录",
"infoEmpty": "没有记录",
"infoFiltered": "(filtered from _MAX_ total records)",
"columns": [ //控制每一列的排序规则
null,
{ "orderDataType": "dom-text", type: 'string' },
{ "orderDataType": "dom-text-numeric" },
{ "orderDataType": "dom-select" }
]
},
stateSave: true, //是否保存table状态
"dom": '<"top"f>rt<"bottom"lp><"clear">', //各个元素的位置
"info":false, //不显示分页详情
"lengthMenu": [[10,15, 20,25,30,40, 50, -1], [10,15, 20,25,30,40, 50,"All"]] //每页显示几条的选项
} );
var table = $('#myTable').DataTable();
$('#myTable tbody').on( 'mouseenter', 'td', function () {
var colIdx = table.cell(this).index().column;
$( table.cells().nodes() ).removeClass( 'highlight' );
$( table.column( colIdx ).nodes() ).addClass( 'highlight' );
} );
} );
/* Create an array with the values of all the input boxes in a column */
$.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
return $('input', td).val();
} );
};
/* Create an array with the values of all the input boxes in a column, parsed as numbers */
$.fn.dataTable.ext.order['dom-text-numeric'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
return $('input', td).val() * 1;
} );
};
/* Create an array with the values of all the select options in a column */
$.fn.dataTable.ext.order['dom-select'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
return $('select', td).val();
} );
};
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
return $('input', td).prop('checked') ? '1' : '0';
} );
};
评论区