Hi, the plugin has no built in sorting functionality except by drag and drop manually. I′m working on a pro version with more functionality, but I′m not done yet. But here is a function you can use to sort by one or more columns:
function table_body_sort_by_columns() {
$args = func_get_args();
$data = array_shift( $args );
foreach ( $args as $n => $field ) {
if ( is_string( $field ) ) {
$tmp = array();
foreach ( $data as $key => $row ) {
$tmp[ $key ] = $row[ $field ];
$args[ $n ] = $tmp;
}
}
}
$args[] = &$data;
call_user_func_array( 'array_multisort', $args );
return array_pop( $args );
}
If you want to sort DESC by the first column:
$data = get_field( 'table' );
$data['body'] = table_body_sort_by_columns( $data['body'], '0', SORT_DESC );
If you want to sort DESC by the second column:
$data = get_field( 'table' );
$data['body'] = table_body_sort_by_columns( $data['body'], '1', SORT_DESC );
As you may have noticed, ‘0’ or ‘1’ identifies the index of the column to sort.
If you want to sort ASC by the first column and sort DESC by the second column:
$data = get_field( 'table' );
$data['body'] = table_body_sort_by_columns( $data['body'], '0', SORT_ASC, '1', SORT_DESC );