【发布时间】:2017-01-02 02:47:32
【问题描述】:
如何添加日期范围过滤器..
喜欢From-To。
我经常进行搜索和分页等工作。 但我不知道如何制作日期范围过滤器。
我使用的是 Datatables 1.10.11 版本。
我的代码:
var oTable;
function callFilesTable($sPaginationType, $bPaginate, $bFilter, $iDisplayLength, $fnSortcol, $fnSortdir){
$.extend($.fn.dataTableExt.oStdClasses, {
sSortAsc : 'header headerSortDown',
sSortDesc : 'header headerSortUp',
sSortable : 'header'
});
oTable = $('#sort').DataTable({
dom : '<"table-controls-top"fl>rt<"table-controls-bottom"ip>',
pagingType : $sPaginationType,
paging : $bPaginate,
searching : $bFilter,
pageLength : $iDisplayLength,
order : [ [$fnSortcol, $fnSortdir] ],
columnDefs : [
{
width : '50%',
targets : [ 2 ],
orderable : true,
searchable : true,
type : 'natural'
},
{
width : '10%',
targets : [ 3 ],
orderable : true
},
{
width : '20%',
targets : [ 4 ],
orderable : true
},
{
targets : ['_all'],
orderable : false,
searchable : false
}
],
language : paginationTemplate,
drawCallback : function() {
checkSelecta();
placeHolderheight();
// hide pagination if we have only one page
var api = this.api();
var pageinfo = api.page.info();
var paginateRow = $(this).parent().find('.dataTables_paginate');
if (pageinfo.recordsDisplay <= api.page.len()) {
paginateRow.css('display', 'none');
} else {
paginateRow.css('display', 'block');
}
}
});
oTable.on( 'length.dt', function ( e, settings, len ) {
updateSession({ iDisplayLength: len });
});
}
我使用的是 NaturalSort 0.7 版本。
【问题讨论】:
-
datatables 网站上有一个范围插件,你看了吗? datatables.net/examples/plug-ins/range_filtering.html
-
@Bindrid 是的,但不起作用。出现错误:未捕获的类型错误:无法读取 Array.
(range_dates.js:30) 处未定义的属性“子字符串” -
我在玩它。如果我得到我的工作,我会发布它
标签: javascript jquery datatables