Losing proper column order when switching columns and sorting
Losing proper column order when switching columns and sorting
Hi,
I'm using server-side version of datatables.
Everything works fine except when I switch columns and use sorting. All the data in rows comes always in the same order in rows (in wrong columns).
When I click sort button, state_save.php and state_load is executed.
When I reload page everything works fine as state_load.php and load_data.php is executed.
It's like the datatables "don't" know what is the current order of columns.
index:
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
var table = $('#example').DataTable( {
serverSide: true,
ajax: 'js/datatables/php/load_data.php?login_uprawnienia={/literal}{$login_uprawnienia}{literal}&id_user={/literal}{$login_id_user}{literal}&id_tabeli=1',
"processing": true,
fixedHeader: true,
"bStateSave": true,
"stateSaveCallback": function (settings, data) {
// Send an Ajax request to the server with the state object
$.ajax( {
"url": "js/datatables/php/state_save.php?id_user={/literal}{$login_id_user}{literal}&id_tabeli=1",
"data": data,
"dataType": "json",
"type": "POST"
} );
},
"stateLoadCallback": function (settings) {
var o;
// Send an Ajax request to the server to get the data. Note that
// this is a synchronous request since the data is expected back from the
// function
$.ajax( {
"url": "js/datatables/php/state_load.php?id_user={/literal}{$login_id_user}{literal}&id_tabeli=1",
"async": false,
"dataType": "json",
"success": function (json) {
o = json;
}
} );
return o;
}
} );
new $.fn.dataTable.ColReorder( table );
} );
</script>
I tried to change ssp.class:
static function data_output ( $columns, $data )
{
$out = array();
for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) {
$row = array();
$row2 = array();
for ( $j=0, $jen=count($columns) ; $j<$jen ; $j++ ) {
$column = $columns[$j];
// Is there a formatter?
if ( isset( $column['formatter'] ) ) {
$row[ $column['dt'] ] = $column['formatter']( $data[$i][ $column['db'] ], $data[$i] );
//$row2
}
else {
$row[ $column['dt'] ] = $data[$i][ $columns[$j]['db'] ];
$row2[ $column['dt2'] ] = $data[$i][ $columns[$j]['db'] ];
}
}
$out[] = $row;
//$out[] = $row2;
}
$out[0][0] = 'test';
return $out;
}
in my 'dt2' is the order of columns in table - in this solution, column are in a good position, but then I switch columns the data "is not going" - it stays in wrong column.
Please help