Sorting problem when fnStateLoad use
Sorting problem when fnStateLoad use
giancorzo
Posts: 2Questions: 0Answers: 0
Hi all,
I have a problem with datatable when using fnStateLoad. Problem is that I get different sorting when I init the page for the first time and I then I get back to the table and I use fnStateLoad.
For example:
First time load:
Name | Visits
Scott | 1
Gian | 2
John | 2
Mary | 2
Second time using fnStateLoad:
Scott | 1
Mary | 2
Gian | 2
John | 2
I ordered by the 2 column, looks like fnStateLoad it's doing it job ok and saving and retrieving the setting but the sorting it's not working ok. This happens for records with the same value.
This the config for my page:
[code]
var datatable = $("#"+this.tableId).dataTable({
"oLanguage": {
"sSearch": "Buscar:",
"oPaginate": {
"sFirst": "Primera página",
"sLast": "Última página",
"sNext": "Próxima página",
"sPrevious": "Página anterior"
},
"sInfo": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
"sInfoEmpty": "Mostrando 0 al 0 de 0 registros",
"sEmptyTable": "No hay registros que mostrar",
"sLengthMenu": 'Mostrar '+
'10'+
'20'+
'30'+
'40'+
'50'+
'Todos'+
' registros'
},
"aoColumns": [
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"iDataSort": 6},
{"iDataSort": 7},
{"bSortable": true},
{"bVisible": false},
{"bVisible": false}
],
aaSorting: [ [2,'desc'],[0,'asc'] ],
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
$.jStorage.set( 'DataTables_'+window.location.pathname+"_clients_table", JSON.stringify(oData) );
$.jStorage.setTTL('DataTables_'+window.location.pathname+"_clients_table", 1000*60*10);
},
"fnStateLoad": function (oSettings) {
if ($.jStorage.get('DataTables_'+window.location.pathname+"_clients_table") !== null) {
settings = oSettings;
}
return JSON.parse($.jStorage.get('DataTables_'+window.location.pathname+"_clients_table") );
}
});
//I was trying this solution with no luck
if (datatableStateLoaded) {
datatable.fnSort([ [settings.aaSorting[0][0],
settings.aaSorting[0][1]]]);
}
[/code]
I have a problem with datatable when using fnStateLoad. Problem is that I get different sorting when I init the page for the first time and I then I get back to the table and I use fnStateLoad.
For example:
First time load:
Name | Visits
Scott | 1
Gian | 2
John | 2
Mary | 2
Second time using fnStateLoad:
Scott | 1
Mary | 2
Gian | 2
John | 2
I ordered by the 2 column, looks like fnStateLoad it's doing it job ok and saving and retrieving the setting but the sorting it's not working ok. This happens for records with the same value.
This the config for my page:
[code]
var datatable = $("#"+this.tableId).dataTable({
"oLanguage": {
"sSearch": "Buscar:",
"oPaginate": {
"sFirst": "Primera página",
"sLast": "Última página",
"sNext": "Próxima página",
"sPrevious": "Página anterior"
},
"sInfo": "Mostrando del _START_ al _END_ de _TOTAL_ registros",
"sInfoEmpty": "Mostrando 0 al 0 de 0 registros",
"sEmptyTable": "No hay registros que mostrar",
"sLengthMenu": 'Mostrar '+
'10'+
'20'+
'30'+
'40'+
'50'+
'Todos'+
' registros'
},
"aoColumns": [
{"bSortable": true},
{"bSortable": true},
{"bSortable": true},
{"iDataSort": 6},
{"iDataSort": 7},
{"bSortable": true},
{"bVisible": false},
{"bVisible": false}
],
aaSorting: [ [2,'desc'],[0,'asc'] ],
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
$.jStorage.set( 'DataTables_'+window.location.pathname+"_clients_table", JSON.stringify(oData) );
$.jStorage.setTTL('DataTables_'+window.location.pathname+"_clients_table", 1000*60*10);
},
"fnStateLoad": function (oSettings) {
if ($.jStorage.get('DataTables_'+window.location.pathname+"_clients_table") !== null) {
settings = oSettings;
}
return JSON.parse($.jStorage.get('DataTables_'+window.location.pathname+"_clients_table") );
}
});
//I was trying this solution with no luck
if (datatableStateLoaded) {
datatable.fnSort([ [settings.aaSorting[0][0],
settings.aaSorting[0][1]]]);
}
[/code]
This discussion has been closed.
Replies
http://debug.datatables.net/uvokuw