• Resolved sesselschwitzer

    (@sesselschwitzer)


    Hello Tobias,

    is there a (simple) way to extend several tr tags with additional classes by a TablePress PHP function?

    At the moment I must look for the correct row-X classes which is – in this case – not nice to handle. But it works!

    A third way could be jQuery but that would be impractical.

    Cheers from Alsfeld/Hessen 🙂
    Sascha

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    If you want to use PHP, you could use a plugin filter hook, like tablepress_row_css_class defined at https://github.com/TobiasBg/TablePress/blob/master/classes/class-render.php#L702

    You could maybe also try the approach from https://wordpress.org/support/topic/highlight-a-row-based-on-value/

    Regards,
    Tobias

    Thread Starter sesselschwitzer

    (@sesselschwitzer)

    Hello Tobias,

    thanks again :). The GitHub link should be the solution. Now I must evaluate how to set the apply_filters args. That should take a while but I will make it work (I hope).

    Cheers and have a nice Sunday
    Sascha

    Thread Starter sesselschwitzer

    (@sesselschwitzer)

    Before searching for a long time:
    How do I get the $row_cells value?

    Thread Starter sesselschwitzer

    (@sesselschwitzer)

    Hups, found it. Sorry …

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    good to hear that this works 🙂

    Best wishes,
    Tobias

    Thread Starter sesselschwitzer

    (@sesselschwitzer)

    Hello Tobias,

    now it really works! My solution:

    add_filter( 'tablepress_row_css_class', 'add_table_row_classes', 10, 5 );
    function add_table_row_classes( $row_classes, $table_id, $row_cells, $row_idx, $row_data ) {
        switch ( $table_id ) {
    
            case 'the-table-id':
    
                if ( in_array( $row_idx, $GLOBALS['tablepress_row']['ids'] ) )
    
                    $row_classes .= ' ' . $GLOBALS['tablepress_row']['css_classes'];
    
                break;
        }
    
        return $row_classes;
    }

    I need the variable $GLOBALS['tablepress_row'] (initialized in tablepress_table_render_data function) to pass parameters to add_table_row_classes function.

    Now I can use simple css like:

    #tablepress-the-table-id tr.example-class td {
    	background-color: moccasin !important;
    }

    Great! Thank you very very much :). Have a nice week

    Cheers
    Sascha

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi Sascha,

    very nice! Thanks for sharing this solution!

    Best wishes,
    Tobias

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Extend tr tags with additional classes’ is closed to new replies.