Okay
  Public Ticket #1025886
Removing sorted class from a column
Closed

Comments

  •  2
    Patrick started the conversation

    Hi,

    I have a couple of columns that I don't want users to be able to sort on, how can I remove the sorted class from them while leaving the others intact. 

    Thanks in advance

  • [deleted] replied

    Hi Patric,

    You can do this on PHP as well as JS side. I wrote little function that you can add to your theme function.php file like in this tutorial and which will allows you to specify column numbers that you do not want to be sortable as well as table id on which you want to apply this:

    function sortColDisable( $object, $table_id ) {
       if ( $table_id == 37 ) {
          $object->dataTableParams->columnDefs[3]->bSortable = false;
          $object->dataTableParams->columnDefs[4]->bSortable = false;
       }
       return $object;
    }
    add_filter('wpdatatables_filter_table_description', 'sortColDisable', 10, 2);

    In this example it will disable sorting on columns 3 and 4 for table with id 37

    Please be aware that numbering is zero based (so first column would be 0) and it counts hidden columns as well

  •  2
    Patrick replied

    Perfect thank you