我正在使用这个Bootstrap table plugin。但按日期排序不正常。
这是代码:
<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>
日期格式为:d/m/y
(17/7/14)
我如何解决它才能正确排序日期?
您必须使用具有“数据分类器”属性的自定义分拣机,如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;
}