• Resolved linkinall

    (@linkinall)


    Good day sir!

    i’m trying to dynamically create N numbers of Tables on the render php file, but I got an error … “Catchable fatal error: Argument 2 passed to TablePress_Table_Model::_add_table_options() must be of the type array, null given, called in /home4/ncbcomni/public_html/bicomni/digitech/bolsa/wp-content/plugins/tablepress/models/model-table.php on line 460 and defined in /home4/ncbcomni/public_html/bicomni/digitech/bolsa/wp-content/plugins/tablepress/models/model-table.php on line 992”

    I created an array and try to call the ADD function… this is my whole function and filter

    add_filter( ‘tablepress_table_render_data’, ‘detalles_cordobas’, 10, 3 );
    function detalles_cordobas( $table, $orig_table, $render_options ) {
    $table_id = 13; // replace with your table id
    $header_row = array( ‘TICKER’, ‘MERCADO’,’MÍNIMO’, ‘PROMEDIO’,’MÁXIMO’); // column names
    $header_row_detail = array( ‘INSTRUMENTO’, ‘PLAZO’, ‘MERCADO’,’MÍNIMO’, ‘PROMEDIO’,’MÁXIMO’); // column names
    $table_id_cord = 18;
    $table_id_details = 19;
    $table_cordobas = array();
    $table_cord = TablePress::$model_table->load( $table_id_cord );
    $table_details = TablePress::$model_table->load( $table_id_details);
    if ( $table_id == $table[‘id’] ) {
    $data_cord = $table_cord[‘data’];
    $data_details = $table_details[‘data’];
    $table_cordobas[0] = $header_row;
    $i = 1;
    foreach($data_cord as $arr)
    {
    $ind_detail_level = 1;
    if (strtoupper($arr[1]) == ‘CORDOBAS’) {
    $tab_detail = array();
    $tab_detail[0] = $header_row_detail;
    //Runs to create the details arrays
    foreach ($data_details as $arr_detail) {
    //Solo los cordobas
    if ($arr_detail[0]==’01’) {
    //Solo los que pertenecen al TICKER ACTUAL
    if ($arr_detail[1] == $arr[2]) {
    $detail_level = array();
    $detail_level[0] = $arr_detail[2];
    $detail_level[1] = $arr_detail[3];
    $detail_level[2] = $arr_detail[4];
    $detail_level[3] = $arr_detail[5];
    $detail_level[4] = $arr_detail[6];
    $detail_level[5] = $arr_detail[7];
    $tab_detail[$ind_detail_level] = $detail_level;
    $ind_detail_level = $ind_detail_level + 1;
    }
    }
    }
    $temp = array();
    reset($arr);
    if ($ind_detail_level > 1) {
    //create the new table
    reset($tab_detail);
    $table_id_details_add = 0;
    $table_id_details_add = TablePress::$model_table->add($tab_detail);
    //create the popmake that will contain the table
    do_shortcode(‘[popup id=”post-“‘. $table_id_details_add .'” size=”medium” title=”‘. $arr[3] .'”] [table id=”‘.$table_id_details_add.'” /][/popup]’);
    $str = ‘“‘.$arr[2].'”“‘;
    $temp[0] = $str;
    }
    else {
    $temp[0] = $arr[2];
    }
    $temp[1] = $arr[4];
    $temp[2] = $arr[5];
    $temp[3] = $arr[6];
    $temp[4] = $arr[7];
    $table_cordobas[$i] = $temp;
    $i = $i +1;
    }
    }
    $table[‘data’] = $table_cordobas;
    }

    return $table;
    }

    I got data from other tables and I try to rename the column name for each ticker, and add a link for a popmake that will show the detail table…

    thanks for any help

    Have a nice day

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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Your code does not really make sense, from what I can see.
    First, you are filtering the current table output. In that, loading other tables is totally fine. I don’t understand why you are trying to save a new table there however. That does not make sense to me.
    Even if this really is what you want, the call to that PHP function is not correct. You can’t just pass the data array but will have to pass the full table array, including things like name, description, options, etc.

    Regards,
    Tobias

    Thread Starter linkinall

    (@linkinall)

    Thank you so much for fast response…

    I was trying to create dynamical tables on the run, using the add method in model_table function. I was able to create them, but I got some Internal data corrupted error, so I decide not to create new tables, but instead create them using simple HTML and datatables CSS for style.

    Now I’m trying to change the background color of the selected row, do you have any idea how to do that?

    Thanks again for this AWESOME plugin!

    Have a nice day! 🙂

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    dynamically creating tables with PHP will work, but you need to use the PHP functions in the proper way (compare the code that TablePress uses to add a new table).
    However, all this does not make any sense inside a render plugin hook.

    Do you mean “selected” row or “hovered” row? How do you select the row? You could then probably just add a CSS class to the row, which has a different background color.

    Regards,
    Tobias

    Thread Starter linkinall

    (@linkinall)

    Sorry, I’m new in PHP. I used the render hook since I need to manually change the first column name and add it a hyperlink to open a popup containing detail table.

    Adding a CSS to the selected row will help me to let the user know which row he/she selected…

    you can take a look at my temp site here : http://www.bi.com.ni/digitech/bolsa/

    Thanks for everything 🙂

    • This reply was modified 9 years, 2 months ago by linkinall.
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    using the render hook for this is fine, but this only influences the current out put. So, saving a table there does not make sense.
    If you instead want to have this change permanent (even visible on the “Edit” screen), then you could do this with PHP but not inside the render hook.

    I still don’t understand the thing with the selected row. Which one is the selected row? How does the user select it?

    Regards,
    Tobias

    Thread Starter linkinall

    (@linkinall)

    Hi Tobias!

    Is ok, I manually create the tables since I have two static tables which reads the csv files automatically.

    About the selected option, user can click on the ¨Ticker¨name, and a popup containing some details will appear; I’ll like to have that row which was clicked, highlighted but only that one… so the user knows which row he/she clicked… it’s like a master detail table, when the master row is clicked, a dropdown container appears and the row stays highlighted in a different color.

    I hope you get the idea.

    Have a nice day!!

    • This reply was modified 9 years, 2 months ago by linkinall.
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    the best approach should then be to use e.g. jQuery to listen to the click on the row. Then, add an extra CSS class to it, which you can use in CSS code for a different background color then.

    Regards,
    Tobias

    Thread Starter linkinall

    (@linkinall)

    Perfect, exactly what I’m doing right now..

    Thanks so much for this AMAZING PLUGIN !! 🙂

    Best wishes!
    Noan

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

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

The topic ‘Add new Table in PHP’ is closed to new replies.