WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] New Features:Show data from DataBase and option to edit data on front end (4 posts)

  1. noslan
    Member
    Posted 10 months ago #

    May be this is so crazy, or may be its not, but is it possible somehow to retrieve data froma database (via sql) and show it in via tablepress? and also, once this data is showed in "dynamic" table, it would be impressive to be able to edit any cell and save changes, m I crazy?

    Thanks!

    http://wordpress.org/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 10 months ago #

    Hi,

    thanks for your question!

    I'm sorry, but this is not possible with TablePress. TablePress can only use its own data format, where the tables are stored as a JSON encoded array in a "Custom Post Type". Accessing custom mySQL database tables is not possible.

    Regards,
    Tobias

  3. uelkfr
    Member
    Posted 8 months ago #

    Is there any hook to modify data before displaying?
    For example, [table id=1 /] is only contain first row (THEAD).
    function get_data_from_database($data, $args)
    if($args['id'] == 1) {
    //global $wpdb; // or WP_Query here
    // row $data[0] is THEAD, so we start from $data[1]
    $data[1][0] = 123; // ID
    $data[1][1] = "Product 1"; // Name
    $data[1][2] = 500; // Price
    }
    return $data;
    }
    add_filter('tablepress_data', 'get_data_from_database');

  4. TobiasBg
    Member
    Plugin Author

    Posted 8 months ago #

    Hi,

    yes, in fact, there are multiple hooks that you could use here (at different stages of the render process, like before formulas are parsed, or before the hidden rows/columns are removed, or before the HTML is generated).
    For the complete details, I suggest to take a look into the "classes/class-render.php" file.

    Here's an example based on your code:

    function table_get_data_from_database( $table, $orig_table, $render_options ) {
      if ( $table['id'] == '1' ) {
        //global $wpdb; // or WP_Query here
        // row $table['data'][0] is THEAD, so we start from $table['data'][1]
        $table['data'][1][0] = '123'; // ID
        $table['data'][1][1] = 'Product 1'; // Name
        $table['data'][1][2] = '500'; // Price
      }
      return $table;
    }
    add_filter( 'tablepress_table_render_data', 'table_get_data_from_database', 10, 3 );

    Regards,
    Tobias

Reply

You must log in to post.

About this Plugin

About this Topic