I found a callback function named "drawCallback" can be used in this kind of case.
https://datatables.net/reference/option/drawCallback
every time dataTable redraw one table page content like you do sorting,
it will be called.
$("#yourTable").DataTable({
"columns":columns,
"ajax": {
"url": url
"dataSrc" : function (json) { return json;}
},
"searching": false ,
"pageLength": rowNumPerPage,
"lengthChange": false,
"autoWidth": false,
"order": [[ 0, "asc" ]],
"drawCallback": function( settings ) {
//for maintaining the same height every page,
//add empty row to table
var api = this.api();
var currentPageDataSet = api.rows( {page:'current'} ).data() ;
if(currentPageDataSet.length < rowNumPerPage){
var $tbody = $('#yourTable tbody');
for(var i = 0; i< rowNumPerPage-currentPageDataSet.length; i++){
var isEven = (currentPageDataSet.length+(i+1))%2 === 0;
var $tr = (isEven)? $('<tr role="row" class="even"></tr>') : $('<tr role="row" class="odd"></tr>');
for(var j=0; j< columns.length; j++){
$tr.append('<td style="color:white;" >_</td>');
}
$tbody.append($tr);
}
}
}
});
In this callback function, what I do is to count the row number of current page
data, if the row number is smaller than the max page row number, then we append empty
row elements to tbody.