WordPress.org

Support

Support » Plugins and Hacks » TablePress » [Resolved] New Features:Show data from DataBase and option to edit data on front end

[Resolved] New Features:Show data from DataBase and option to edit data on front end

  • 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/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author TobiasBg

    @tobiasbg

    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

    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’);

    Plugin Author TobiasBg

    @tobiasbg

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] New Features:Show data from DataBase and option to edit data on front end’ is closed to new replies.
Skip to toolbar