forfun109
Forum Replies Created
-
Forum: Plugins
In reply to: [ULTIMATE TABLES] How To Make Data Display in Reverse OrderI faced on a similar problem :
On first display, to sort descending
To keep sorting by click on column headerI failed by use of javascript datatables parameter “aoColumnDefs”: [
{ "asSorting": [ "desc", "asc" ], "aTargets": [ 0 ] } ]
. It seems that the runtime layer forces an ascending sort after this instruction …
The workaround I used with success on my side is:
to add a column ‘Number’ which contains values in a reverse order than the column I want to sort descending.
To add javascript code in the ultimate-tables/init.php file, with the WordPress Edit Plugin Editor.
In the default sequence :<script type="text/javascript" charset="utf-8"> jQuery(document).ready(function() { jQuery(\'#table_'.$id.$contador.'\').DataTable( {"destroy": true,"bPaginate": '.$ispagination.',"bLengthChange": '.$op5.',"bFilter": '.$op1.',"bSort": '.$op2.',"bInfo": '.$op3.',"bStateSave": true,"bAutoWidth": '.$sizedescription.',"sPaginationType": "'.$typepagination.'",'.$heighttable.''.$sizetitle.'} ); });
I added
,"aoColumnDefs": [{ "bVisible": false, "aTargets": [ 0 ] }, { "iDataSort": 0, "aTargets": [ 1 ] }]
The new column ‘Number’ is column 0 and I hide it; Values of column 0 are used to sort the target, column 1.The new sequence is now
<script type="text/javascript" charset="utf-8"> jQuery(document).ready(function() { jQuery(\'#table_'.$id.$contador.'\').DataTable( {"destroy": true,"bPaginate": '.$ispagination.',"bLengthChange": '.$op5.',"bFilter": '.$op1.',"bSort": '.$op2.',"bInfo": '.$op3.',"bStateSave": true,"bAutoWidth": '.$sizedescription.',"sPaginationType": "'.$typepagination.'",'.$heighttable.''.$sizetitle.',"aoColumnDefs": [{ "bVisible": false, "aTargets": [ 0 ] }, { "iDataSort": 0, "aTargets": [ 1 ] }]} ); });
It’s probably not the most elegant manner, but it works …