[英]Filter by date range in Datatable problem
我正在數據表中實現日期范圍過濾器,當以YYYY-MM-DD格式顯示列日期時,過濾器工作正常,但我需要以DD-MM-YYYY格式顯示列,所以我應用了一下。
使用數據表中的時刻的回調函數:
{ targets : [8],
render : function (data, type, row) {
return moment(data).format('DD/MM/YYYY')
}
},
結果我看到第二天顯示在列上。 圖片如下。 我想按日期過濾,列按以下格式DD / MM / YYYY排序
顯然我在datepicker過濾器中選擇了第10天,它在桌子上顯示第11天。
$(document).ready(function(){
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var fecha_inicio = $('#fecha_inicio').datepicker("getDate");
// alert(fecha_inicio);
var fecha_fin = $('#fecha_fin').datepicker("getDate");
var arr = data[8].split('/').reverse().join('-');
// alert(arr);
// var temp = arr[0] +'-'+ arr[1] +'-'+arr[2];
var startDate = new Date(arr);
startDate.setHours(0,0,0,0);
// alert(startDate);
if (fecha_inicio == null && fecha_fin == null) { return true;}
if (fecha_inicio == null && startDate <= fecha_fin) { return true;}
if(fecha_fin == null && startDate >= fecha_inicio) { return true;}
if (startDate <= fecha_fin && startDate >= fecha_inicio) { return true;}
return false;
}
);
如果我取出回調代碼,則列顯示正確,但日期格式除外。
提前致謝。
也許你想使用type
參數,例如
render:function(data,type,row,meta){
if(type=='display'){
return moment(data).format('DD/MM/YYYY');
}
if(type=='filter'){
//there is an example, show how to work, you can use whatever you want time format
return moment(data).format('YYYY/MM/DD');
}
if(type=='sort'){
//maybe there is timestamp format
return data;
}
return data;
}
有關更多詳細信息,請檢查https://datatables.net/reference/option/columns.render function render( data, type, row, meta )
部分
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.