我使用PHP创建了表格& MySQL与Datatables插件,我试图用DD.MM.YYYY排序我的列。格式,但它似乎不工作,因为我喜欢它。它仅使用第一个数字排序。 这里是我的代码Datatables日期排序(DD.MM.YYYY。)格式
$(document).ready(function() {
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
var datum = day + "." + month + "." + year + ".";
var doc = day + month + year;
$(document).ready(function() {
$.fn.dataTable.moment('DD.MM.YYYY.');
$('#pogled_ispu').removeAttr('width').DataTable({
dom: 'Bfrtip',
scrollY: "500px",
scrollX: true,
scrollCollapse: true,
paging: false,
select: true,
columnDefs: [{
width: 10,
targets: 8
}],
fixedColumns: {
leftColumns: 0
},
buttons: [
'colvis',
'pageLength', {
extend: 'excelHtml5',
text: '<i class="fa fa-file-excel-o"></i>',
titleAttr: 'Preuzimanje u excel formatu',
title: 'Tablični prikaz_' + datum,
exportOptions: {
columns: ':visible'
}
}, {
extend: 'pdfHtml5',
orientation: 'landscape',
text: '<i class="fa fa-file-pdf-o"></i>',
titleAttr: 'Preuzimanje u PDF formatu',
title: 'Prostorno planska dokumentacija',
message: 'Prostorno planska dokumentacija ' + datum,
pageSize: 'A3'
}
],
language: {
"url": "js/Croatian.json",
buttons: {
colvis: '<i class="fa fa-eye"></i>',
pageLength: 'Broj redova'
}
}
});
});
});
,这里是插件的日期时间排序:
$.fn.dataTable.moment = function (format, locale) {
var types = $.fn.dataTable.ext.type;
// Add type detection
types.detect.unshift(function (d) {
return moment(d, format, locale, true).isValid() ?
'moment-'+format :
null;
});
// Add sorting method - use an integer for the sorting
types.order[ 'moment-'+format+'-pre' ] = function (d) {
return moment(d, format, locale, true).unix();
};
};
它是问题(DD.MM. YYYY。)格式。我应该省略最后一个点吗?
我想你传递日期时间格式的字符串转换成数据表 –