• Resolved jools73

    (@jools73)


    Tobias – love the plug-in!!! Thank you

    Is it possible to extract properties from a table? In particular, i’d like to know how many rows there are in a TablePress table

    I need to be able to loop through a Table and do some conditional stuff which I should be able to do with PHP and the Single Cell Content Shortcode extension, but I need to know how many rows I need to loop through.

    https://www.ads-software.com/extend/plugins/tablepress/

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your question.

    Yes, you can get the number of rows from the table-info Shortcode (or Template Tag function), like this:

    [table-info id=123 field=number_rows /]

    This does take the table head row into account, so double check the number first.

    Now, if you want to loop through a table before it is rendered, it might actually be easier to hook into a TablePress filter hook like tablepress_table_raw_render_data (see class-render.php), where you have access to the table data array in PHP.

    Regards,
    Tobias

    Tobias,

    In a similar fashion, can I create a custom table from a master table? For example, a table with a specific customers information only.

    I see there are no “tables” created in the database and the info resides in the wp_posts table but all the data is in one cell.

    any suggestions?

    J

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    yes, tables are stored as a JSONified two-dimensional array in a Custom Post Type in wp_posts (and thus do not allow direct querying).
    However, for your use case, the TablePress Row Filter Extension from https://tablepress.org/extensions/row-filter/ should be useful.

    Regards,
    Tobias

    Perfect! works for what I need.

    thanks.

    Jason

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Jason,

    very cool! Great to hear that this will help!

    Best wishes,
    Tobias

    Another question… Is there a way to exclude a column? I didn’t notice an extension that did.

    Please advise…

    Jason

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    do you mean to exclude a column from being shown to the visitor, but being visible on the “Edit” screen?
    Just use the “Hide” button below the table input fields (after clicking the column’s checkbox below it), or use the corresponding hide_columns Shortcode parameter that is described in the section “The Shortcode [table id=N /]” in the TablePress Documentation at https://tablepress.org/documentation/
    No Extension necessary for that ??

    Regards,
    Tobias

    Thanks but I would like to be able to see it on front end for internal team but exclude a column when filtering by customer on their custom page. I do not want them to see costs that we need internally.

    Does that make sense?

    Jason

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Jason,

    does “internal team” mean people who are logged-in into WordPress? Then you could use the TablePress Extension from https://tablepress.org/extensions/hide-data-logged-out-users/
    With that, you’ll get the new Shortcode parameter “hide_columns_logged_out” that will hide the stated columns only to users who are not logged-in into WordPress.

    Regards,
    Tobias

    Tobias,

    Sorry for the confusion. We have some customers that are logged-in in addition to employees that monitor the reports. I don’t want customers to view certain columns but employees to be able to.

    Does that clear it up?

    Jason

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Jason,

    ok, so how do you distinguish between them from technical point of view?
    If the Extension had something to decide whether a user is allowed to see the column or not, that could be changed rather easily in the Extension’s PHP file.

    Regards,
    Tobias

    I am ok with table with all columns on one page and a table with specific columns selected on the other.

    I don’t expect the table to react based on who is logged in really. I will have unique pages for the data I want filtered.

    My goal is to create a new page for a specific customer that filters only data they need to see plus hide specified columns.

    Jason

    Would I be able to edit the Extension’s PHP File based on “USER” type? For example, if their user classification is “Customer”, could the tables output be affected based on that variable?

    Whereas…”Admin” could see everything?

    Jason

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    well, if you are ok with having the tables on different pages, just use different Shortcodes.
    On the page with the table for the internal team you would just use the Shortcode with the “filter” parameter, and on the page with the table for the customers, you could add the extra “hide_columns” parameter, additionally to the “filter” parameter.

    Adjusting the Extension to certain user types (“roles” in WordPress) should be possible, but would require some custom coding. As I can’t provide that as free support at the moment, I recommend to try that approach with the different Shortcodes on the pages.

    Regards,
    Tobias

    You are the man! The “hide_columns” works perfectly!

    Out of curiosity, why use the “||” separator on “filter” and “,” on “hide_columns” to hide multiple? Just trying to figure the shortcodes out.

    Thanks again!

    Jason

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Query number of rows in a Table’ is closed to new replies.