admin管理员组文章数量:1316974
I need to sort a column by weekdays (mon, tue, wed, thu, fri, sat, sun) and cannot seem to get this working. Note that I am using the latest 1.10 version of datatables.
This is located along with other extensions in its own file and called after jquery.dataTables.js is loaded, but before the table initialization.
/* custom sorting by weekday */
$.extend( $.fn.dataTableExt.oSort, {
"weekday-pre": function ( a ) {
return $.inArray( a, ["SUN","MON","TUE","WED","THU","FRI","SAT"] );
},
"weekday-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"weekday-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
then in my table initialization I specify the sort for this particular column. Values can/will only be "SUN","MON","TUE","WED","THU","FRI","SAT" ing from the database.
"columns": [
..... some column entries,
{
"data": "day",
"type": "weekday"
},
..... the rest of the column entries
No errors in the console, however, sorting just defaults to the regular alphabetical sorting when I sort by clicking on the column title.
I need to sort a column by weekdays (mon, tue, wed, thu, fri, sat, sun) and cannot seem to get this working. Note that I am using the latest 1.10 version of datatables.
This is located along with other extensions in its own file and called after jquery.dataTables.js is loaded, but before the table initialization.
/* custom sorting by weekday */
$.extend( $.fn.dataTableExt.oSort, {
"weekday-pre": function ( a ) {
return $.inArray( a, ["SUN","MON","TUE","WED","THU","FRI","SAT"] );
},
"weekday-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"weekday-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
then in my table initialization I specify the sort for this particular column. Values can/will only be "SUN","MON","TUE","WED","THU","FRI","SAT" ing from the database.
"columns": [
..... some column entries,
{
"data": "day",
"type": "weekday"
},
..... the rest of the column entries
No errors in the console, however, sorting just defaults to the regular alphabetical sorting when I sort by clicking on the column title.
Share Improve this question edited Feb 27, 2014 at 2:40 user756659 asked Feb 27, 2014 at 2:17 user756659user756659 3,51213 gold badges59 silver badges118 bronze badges1 Answer
Reset to default 6Got this working with dataTables 1.10.0-beta.2:
$(function() {
$('#datatable').DataTable({
"oLanguage": {
"sSearch": "Filter Data"
},
"iDisplayLength": -1,
"sPaginationType": "full_numbers",
"aoColumns": [{
"sType": "weekday"
},null]
});
});
Note that i just defined a type in aoColumns. The actual sorting is still done by your code.
Look at this Plunk and tell me if this is what you wanted. (Tested on Chrome cuz FF is a little bit picky when it es to dataTables and Plunker)
本文标签: javascriptdatatables 110 and custom sorting functionStack Overflow
版权声明:本文标题:javascript - datatables 1.10 and custom sorting function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742021342a2414731.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论