net*_*dev 6 html javascript php jquery bootstrap-table
我正在使用这个Bootstrap 表插件。但是按日期排序不能正常工作。
这是代码:
<table class=" table-striped" id="table" data-toggle="table"
data-search="true"
data-filter-control="true"
data-click-to-select="true"
data-escape="false">
<thead>
<tr>
<th data-field="expiry_date" data-sortable="true" scope="col"><?= 'expiry date' ?></th>
</tr>
</thead>
Run Code Online (Sandbox Code Playgroud)
日期格式如下:d/m/y(17/7/14)
我如何修复它以正确排序日期?
您必须使用具有“data-sorter”属性的自定义排序器,例如 data-sorter="datesSorter"
然后满足您的需求:
function datesSorter(a, b) {
if (new Date(a) < new Date(b)) return 1;
if (new Date(a) > new Date(b)) return -1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)