• jessica

    (@passionfordesigns)


    I’m not a developer and tried to sort my table by descending, sounds quiet simple, but it does not work for me, maybe I don’t have enough knowledge about the code..

    Would u be so kind to give me an example for sorting the tables by descending, or is this not possible?

Viewing 1 replies (of 1 total)
  • Plugin Author Johann Heyne

    (@jonua)

    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 );
Viewing 1 replies (of 1 total)
  • The topic ‘Sort bij descending?’ is closed to new replies.