我想按自定义顺序对数据表进行排序。例如,人的位置/等级。不是数字,也不是字母数据排序。有人有什么想法吗?
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>Manager</td>
<td>Edinburgh</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>CEO</td>
<td>Tokyo</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Janitor</td>
<td>San Francisco</td>
</tr>
</tbody>
<table>
我尝试了以下但无法弄清楚
$(document).ready(function() {
$('#example').DataTable({
"columnDefs": [{
"type": "CEO",
"targets": 1
},
{
"type": "Manager",
"targets": 2
} {
"type": "Janitor",
"targets": 3
}
]
});
});
答案 0 :(得分:0)
我想通了
$.fn.dataTable.ext.type.order['ranking-pre'] = function ( d ) {
switch ( d ) {
case 'CEO': return 1;
case 'Manager': return 2;
case 'Janitor': return 3;
}
return 0;
};
$('#example').dataTable( {
"columnDefs": [ {
"type": "ranking-level",
"targets": 1
} ]
});