I am building a custom WordPress plugin where I create a native list for entities in a custom database table.

The iteration of the rows happens inside this function:

public function column_default( $item, $column_name )
    global $wpdb;
    switch( $column_name ) {            
        case 'elap_electioncitizen_electionnum':
            $actions = array(
                        'view'      => sprintf('<a href="?page=%s&action=view&electionnum=%s">Προβολή</a>', $_REQUEST['page'], $item['elap_electioncitizen_electionnum']),
                        'allocate'      => sprintf('<a href="' . home_url( $path = '/wp-content/plugins/elections/allocate_child.php?noheader=true') . '&electionnum=%s">Allocate</a>', $item['elap_electioncitizen_electionnum'])

            return sprintf('%1$s %2$s', $item[ $column_name ], $this->row_actions($actions) );
        case 'elap_electioncitizen_surname':
        case 'elap_electioncitizen_firstname':
        case 'elap_electioncitizen_fathername':
        case 'elap_electioncitizen_birthdate':
        case 'elap_electioncitizen_cityarea':
            return $item[ $column_name ];
        case 'elap_electioncitizen_address':
            return $item[ 'elap_electioncitizen_street' ] . " " . $item[ 'elap_electioncitizen_streetnumber' ];
            return print_r( $item, true ) ;

My question is, how can assign each row a different class based on criteria from the database?

For example, each electioncitizen that has no cityarea must appear with a yellow background in the list.

Read more here: Custom WP_List_Table: Style each row using column_default


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: