WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded
[resolved] Table Row CSS (4 posts)

  1. swcomm
    Member
    Posted 3 years ago #

    Is there a way I can refer to data in a table cell or some other hidden field to grab the CSS selector or row background color to use in the custom CSS area? I have a series of tables that are color-coded by row, and need each datarow to be one of two colors, but the colors used are not alternating rows -- for example, I may have 6 consecutive rows of data using color 1, followed by one row of data using color 2, etc. I was thinking I'd put the color selector or RGB value into its own cell in each record, using a hidden column, but can't figure out how I'd refer to that cell/field in the custom CSS.

    Or, is there another way to do this? Hope I explained what I'm looking for.

    Fabulous plugin, thanks a bunch.

  2. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    Hi,

    I believe I understood what you want to achieve. Unfortunately, this is not that easy.
    There is no way that CSS can access the content of a table, especially not a hidden column, as the CSS will never see that column as well. (There might be developments in CSS in the future that allow such kind of dynamic queries, however, that's still in the future.)

    So, instead, you should look into a JavaScript solution:
    Mark your rows with an empty HTML of some kind (e.g. insert an empty <span class="type-1"></span> or <span class="type-2"></span> into a cell).
    Then, the JavaScript (with jQuery this should be easily possible) could loop through the rows, look for that <span>, grab the class, and add that to the actual row's classes. Your CSS would then only contain the actual stying for the type-1 and type-2 classes, while the actual work is done by JavaScript.

    Best wishes,
    Tobias

  3. swcomm
    Member
    Posted 3 years ago #

    Thanks for your reply. Span doesn't exactly give me what I want, so after playing around with this a bit, thought I'd share how I resolved it.

    I turned off all of the default and custom CSS generated by your plugin and added a function to my function.php file that lets me enter custom CSS per post/page. I then style the tables using my theme CSS and style the rows using your selector ids in the custom CSS in each post/page - gives me complete control over my row colors. It's quite a bit of inline CSS, but I really need the ability to use more than one set of custom CSS to style these rows, so styling at the post level seemed to be the best solution.

    Thanks again for your help - as soon as I get paid for the project, will send you a donation!

  4. TobiasBg
    Member
    Plugin Author

    Posted 3 years ago #

    Hi,

    thanks for the feedback and the report on how you solved it! Sounds reasonable and workable to me :-) Maybe it will also be helpful to others, so thanks for sharing it!

    Best wishes,
    Tobias

    P.S.: And great to hear about that upcoming donation, I really appreciate it! Thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic