Reset order/sort by default

Reset order/sort by default

Ludoludo75Ludoludo75 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:

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    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

  • Ludoludo75Ludoludo75 Posts: 41Questions: 8Answers: 0

    Hi,

    Thanks,

    I have 1.10.16

    I use "dataTable"

    I have this error :

    TypeError: dt.table().fnSortNeutral is not a function. (In 'dt.table().fnSortNeutral([])', 'dt.table().fnSortNeutral' is undefined)

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited November 2018

    I use "dataTable"

    It runs here without the error using "dataTable":
    http://live.datatables.net/qiquqiko/2/edit

    Did you load the plugin code?

    Kevin

  • Ludoludo75Ludoludo75 Posts: 41Questions: 8Answers: 0

    Mmh

    Ok thanks, and with a button to re-order that after initialization ?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    Try this:
    http://live.datatables.net/qiquqiko/3/edit

    Your code dt.table().fnSortNeutral([]); definitely is not going to work.

    Kevin

  • Ludoludo75Ludoludo75 Posts: 41Questions: 8Answers: 0

    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(); } }

  • Ludoludo75Ludoludo75 Posts: 41Questions: 8Answers: 0

    Ok but... it takes up html order, but I would like this button takes default ordering included in parameter "order"

    Any solutions ? :/

    Thanks

  • Ludoludo75Ludoludo75 Posts: 41Questions: 8Answers: 0

    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

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    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() in initComplete. For example:
    http://live.datatables.net/fixewolu/1/edit

    Kevin

  • Ludoludo75Ludoludo75 Posts: 41Questions: 8Answers: 0

    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 :)

  • Ludoludo75Ludoludo75 Posts: 41Questions: 8Answers: 0

    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

This discussion has been closed.