我已定义此数据表,但默认情况下是按第一列排序,我希望它按第二列排序
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
var table = $('#producersTableId').DataTable({
"dom": '<"top">rt<"bottom"lp><"clear">',
"autoWidth": false,
"columnDefs": [
{"targets": [0], "width": '20%'},
{"targets": [1], "width": '20%'},
{"targets": [2], "width": '35%'},
{"targets": [3], "width": '15%'},
]
});
table.columns().every( function () {
var that = this;
$( 'input', this.header() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
});
答案 0 :(得分:1)
您需要指定'order'属性:
$(table).DataTable({
order: [[1, 'asc']] // where the number is index of the column (i think zero besed)
// so in your case second column is with index 1
});
查看https://datatables.net/examples/basic_init/table_sorting.html