Arat Kumar rana
Arat Kumar rana

Reputation: 187

reset to default sorting in jquery datatable

I have a page on which one dropdown as Report1 and Report2 is there. If I select Report1 it will populate startdate and enddate. I will select startdate and end date then cliick on view report it will do ajax call and fetch the data and displaying in table, I am using datatable for this.

I have default sorting of the second coulmn and also I can able to sort other column. If I sort other column and then select the other report Report2 and then select startdate adn end date and then hit the view report button. Again If I select the Report1 and startdate and end date and hit the view report button, it is sorting the other column but not the default sorting column. Any help would be appreciable.

Below is my code

$('#userTable').dataTable({
                        "bProcessing" : false,
                        "bServerSide" : false,
                        "bFilter" : false,
                        "bSearchable" : false,
                        "oLanguage" : {
                            "sZeroRecords" : "No Active Users Found",
                            "sInfo" : "Total Records Found: _TOTAL_ "
                        },
                        "aaSorting" : [ [ 2, "asc" ] ],
                        "aoColumnDefs" : [ {
                            "mData" : "emailAddr",
                            "sWidth" : "20%",
                            "aTargets" : [ 0 ]
                        }, {
                            "mData" : null,
                            "sWidth" : "20%",
                            "mRender" : function(data, type, row) {
                                return row.firstNm + ' ' + row.lastNm;
                            },
                            "bSortable" : false,
                            "aTargets" : [ 1 ]
                        }, {
                            "mData" : "retailerId",
                            "sWidth" : "20%",
                            "aTargets" : [ 2 ]
                        }, {
                            "mData" : "role",
                            "sWidth" : "20%",
                            "aTargets" : [ 3 ]
                        }, {
                            "mData" : "contactPhone",
                            "bSortable" : false,
                            "sWidth" : "20%",
                            "aTargets" : [ 4 ]
                        } ],
                        "fnInfoCallback": function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {       
                            return 'Displaying '+iStart+' to '+iEnd+' of ' +iTotal + ' entries';
                }

Upvotes: 0

Views: 3930

Answers (2)

Jitesh Sojitra
Jitesh Sojitra

Reputation: 4043

Please use this way:

var DTable = $("<your table>").dataTable ({
...
..
}

setInterval( function () {
        DTable.fnClearTable( 0 );
        DTable.fnSort( [ 0, "desc" ] );
        DTable.fnDraw();

    }, 5000 );

Upvotes: 1

Atanas Desev
Atanas Desev

Reputation: 868

If I understood you correctly you want to a function that will return the default order? If that is the case I think that the following will be helpfull:

http://datatables.net/plug-ins/api/fnSortNeutral

Upvotes: 0

Related Questions