Reset order/sort by default
Reset order/sort by default
Ludoludo75
Posts: 41Questions: 8Answers: 0
Hi,
I would like to reset the order of the columns as started
I try to use : fnSortNeutral
But i can't, I don't know why
`$.extend( $.fn.dataTable.defaults, {
"dom": '<"top"AfB>rt<"bottom"ip><"clear">',
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.16/i18n/French.json",
"decimal": ",",
"thousands": ".",
"language": {
alphabetSearch: {
alphabet: '#ABCDEFGHIJKLMNOPQRSTUVWXYZ',
infoDisplay: 'Afficher :',
infoAll: 'Tous'
}
}
},
"paging": true,
"pagingType": "full_numbers",
"ordering": true,
"searching": true,
"info": false,
"pageLength": 25,
fixedHeader: {
header: true,
footer: true
},
buttons: [
{
text: 'Ordre par défaut',
action: function ( e, dt, node, config ) {
dt.table().fnSortNeutral([]);
}
}
]
} ); `
thanks
This question has accepted answers - jump to:
This discussion has been closed.
Answers
What version of Datatables are you using?
fnSortNeutral is meant for DT 1.9 but according to this thread it may work with 1.10.
https://datatables.net/forums/discussion/comment/69657/#Comment_69657
What exactly happens? Do you get console log messages?
If using 1.10 you may want to read the this:
https://datatables.net/plug-ins/api/#Legacy-plug-ins
Have you tried without passing the empty array, like this?
dt.table().fnSortNeutral();
Kevin
Hi,
Thanks,
I have 1.10.16
I use "dataTable"
I have this error :
It runs here without the error using "dataTable":
http://live.datatables.net/qiquqiko/2/edit
Did you load the plugin code?
Kevin
Mmh
Ok thanks, and with a button to re-order that after initialization ?
Try this:
http://live.datatables.net/qiquqiko/3/edit
Your code
dt.table().fnSortNeutral([]);
definitely is not going to work.Kevin
YEAHH
Really thank you,
To catch the id of the table, I wrote :
{
text: 'Ordre par défaut',
action: function ( e, dt, node, config ) {
$( '#' + dt.table().node().id ).dataTable().fnSortNeutral();
}
}
Ok but... it takes up html order, but I would like this button takes default ordering included in parameter "order"
Any solutions ?
Thanks
I tried with
dt.order( [[5, 'asc'],[4, 'asc'],[3, 'asc'],[2, 'asc']] ).draw( false );
It works
But I would like to automatically "catch" parameter "order" of the datable $('#example').DataTable
If that legacy API doesn't work for you then I would suggest using a global variable and saving the original order into that variable using
order()
ininitComplete
. For example:http://live.datatables.net/fixewolu/1/edit
Kevin
YEAH really thank you, it looks like my first idea
But I have to code each global variable, it's not just one to catch the order of the active table, too bad, but maybe in the next version
@allan
Thank you @kthorngren
EDIT : finally, I wrote the code in fnInitComplete of
$.extend( $.fn.dataTable.defaults ..
for automatizing, BUT
If I change the order when it's initialized, the button doesn't work well because it takes the value after the complete initialization of the table (during this time, the user can change the order as he wishes)
Maybe a solution ?
I don't know how to use "preInit"
Thanks