jorgeantolin7
Forum Replies Created
-
Hi Tobias,
You helped me solve this problem with my filter 4 months ago. Now with the last update of TablePress it doesn’t work anymore… I keep using the shortcode [table id=1 filter=3 /] but it doesn’t filter anything (it should show rows which column Price is > 3).
Any idea why this is happening now?
Thanks and best regards,
Jorge.
Hi Tobias,
Nice, I got it working! Thank you very much, I really appreciate your help, it was very useful!
Best regards,
Jorge.
Hi Tobias,
Thank you so much, now I understand what to do and I am able to do it.
I just have one last question, how does the $render_options param work?Imagine I want to pass a number (‘2’) so it filters the rows that have less ‘Price’ than 2. I’d do it by passing it in the Shortcode:
[table id="4" filter="2" /Then I verify if no parameter is given or an empty “filter” one:
if ( empty( $render_options['filter'] ) ) { return $table; } $filter = $render_options['filter'];But I am not able to capture the parameter filter in the Shortcode. Any idea why?
Best regards,
Jorge.- This reply was modified 8 years ago by jorgeantolin7.
- This reply was modified 8 years ago by jorgeantolin7.
Hi Tobias,
I understand the filter hook now much better, thanks. Now I wanted to try if I am able to hide rows, I tried to hide all rows from the table but I got an error. This is my code:
add_filter('tablepress_table_raw_render_data', 'jorge_filter_tablepress_table', 10, 2 ); function jorge_filter_tablepress_table( $table, $render_options ) { // Do something with the table data. $hidden_rows = array(); foreach ( $table['data'] as $row ) { //if ($row[3] < 2){ $hidden_rows[] = $row; //} } // Remove the rows that shall be hidden from table data and table visibility. foreach ( $hidden_rows as $row_idx ) { unset( $table['data'][ $row_idx ] ); unset( $table['visibility']['rows'][ $row_idx ] ); } // Reset array keys. $table['data'] = array_merge( $table['data'] ); $table['visibility']['rows'] = array_merge( $table['visibility']['rows'] ); return $table; } function filtering_rows_function($atts) { extract(shortcode_atts(array('id' => 1,), $atts)); $attributes['id'] = preg_replace( '/[^a-zA-Z0-9_-]/', '', $id ); $table = tablepress_get_table( $attributes ); return jorge_filter_tablepress_table($table); }My problem is in the
$table['visibility']['rows'] = array_merge( $table['visibility']['rows'] )part I think, (if I just comment this last row then the whole table is shown). Do you know how can I fix this?Thank you so much and best regards,
Jorge.
- This reply was modified 8 years ago by jorgeantolin7.
- This reply was modified 8 years ago by jorgeantolin7.
- This reply was modified 8 years ago by jorgeantolin7.
Hi Tobias,
I am sure I am making some mistake because nothing is showing after I wrote this following code in the ‘functions.php’ file of my WordPress page:
add_filter('tablepress_table_raw_render_data', array( __CLASS__, 'filter_rows' ), 10, 1 ); function filter_rows($table){ foreach ($table['data'] as $row){ echo $row['Price']; } return; } function filtering_rows_function($atts) { extract(shortcode_atts(array('id' => 1,), $atts)); $attributes['id'] = preg_replace( '/[^a-zA-Z0-9_-]/', '', $id ); $table = tablepress_get_table( $attributes ); return filter_rows($table); } function register_shortcodes(){ add_shortcode('filtering_rows', 'filtering_rows_function'); } add_action('init', 'register_shortcodes');Can you spot my error? And I don’t understand where do the ‘tablepress_table_raw_render_data’ and array( __CLASS__ come from exactly.
Thanks and sorry for too much messages,
Jorge.
- This reply was modified 8 years ago by jorgeantolin7.
Hi,
Okay I understand it now, my problem is that $table is already HTML code for me. I have tried to include this, as you told me:
add_filter( 'tablepress_table_raw_render_data', array( __CLASS__, 'filter_rows' ), 10, 2 );But it is not working. Where should I include it in my code? And what do I need to be able to include it, do I need any specific extension or import?
I do not understand how can I get my $table as a 2 dimensional array.
Thanks for your answer and regards,
Jorge.Hi,
Okay thanks, and how should I continue in the part of my code where I should get the hidded_rows array..? Can you help me with the foreach loop? I am really new to PHP.
Thank you and best regards,
Jorge.Hi Tobias,
This is how my code in my “functions.php” file looks like now:
function filter_rows($table){ // Rows that do not match the filter: Column Price < 3 $hidden_rows = array(); // Here I should get the hidde_rows array... foreach ( $hidden_rows as $row_idx ) { unset( $table['data'][ $row_idx ] ); unset( $table['visibility']['rows'][ $row_idx ] ); } $table['data'] = array_merge( $table['data'] ); $table['visibility']['rows'] = array_merge( $table['visibility']['rows'] ); return $table; } function filtering_rows_function($atts) { extract(shortcode_atts(array('id' => 1,), $atts)); $attributes['id'] = preg_replace( '/[^a-zA-Z0-9_-]/', '', $id ); $table = tablepress_get_table( $attributes ); return filter_rows($table); } function register_shortcodes(){ add_shortcode('filtering_rows', 'filtering_rows_function'); } add_action('init', 'register_shortcodes');So should I add this line too?
add_filter( 'tablepress_table_raw_render_data', array( __CLASS__, 'filter_rows' ), 10, 2 );I am struggling to get the $hidden_rows array in my code…
Best regards and thank you so much for your answer,
Jorge.
Hi Tobias,
Thanks for your answer. I am having a look at the PHP code of the Row Filter Extension but I do not understand how you iterate through each row of a table.
Let’s say I have a table in a variable $table such that if I do “return $table”, then in my WordPress page I get the table. Is there any PHP method that allows me to get the rows of the $table and the value of a certain column of these rows?
Best regards,
Jorge.Hi Tobias,
Thank you very much for your answer. I have tried that TablePress Extension already but unfortunately it does not work for my case since this “Price” column can take arbitrary values.
Is it possible to do it modifying the Shortcode as you explained here: https://tablepress.org/faq/documentation-shortcode-table/ ? My problem is to get the list of rows that don’t satisfy my condition. Do you know if I can get those values with PHP or JS? Maybe adding something to the “Custom Commands” when editing the table in WordPress?
Best regards,
Jorge.