Hi,
thanks for your post, and sorry for the trouble.
No, sorry, that’s not directly possible, as formulas in TablePress only work with numbers, but not text strings.
Your best chance, if you want to prevent copy/paste would be to do this e.g. in Excel, then save the table as a CSV file and then re-import that into TablePress.
Regards,
Tobias
Thread Starter
0cg0
(@0cg0)
Hi Tobias,
the problem is not to populate the column but to avoid writing the same string thousands of times.
Is it possible to overwrite cells with custom commands or with a php function?
Thanks for the reply.
Hi,
then, a possible solution might be to define a custom Shortcode (with PHP code) that returns the desired text, and to then use that Shortcode in the table cells.
Regards,
Tobias
Thread Starter
0cg0
(@0cg0)
Hi Tobias,
but through columnDefs:
is it possible to overwrite the cells?
Thanks for the reply.
Hi,
you could indeed also look into using JavaScript for this, if it’s always the same content. You would need a render
callback in the columnDefs
then, see e.g. https://wordpress.org/support/topic/changing-links-to-click-here-for-an-entire-column/
Regards,
Tobias
Thread Starter
0cg0
(@0cg0)
Hi Tobias,
it works thanks.
The problem is that it only works with static strings, in my case I generate the url dynamically with php, and therefore it doesn’t work.
Maybe just with a php solution it could work, but I didn’t understand if I should insert the Shortcode you suggest directly into the cell.
Thanks for the reply.
Hi,
yes, I meant to insert the Shortcode directly into the cell. It would return the desired link HTML then.
But then, from what I now understand, the URL is not actually the same in every row? What’s the difference then? Can you maybe make your example more detailed?
Regards,
Tobias
Thread Starter
0cg0
(@0cg0)
Hi Tobias,
the string in the cell is always the same but the generated HTML is dynamic:
=<a href="<?php echo esc_url( '/directory/' . $_GET['xyz'] . '?test={ROW}', ENT_QUOTES); ?>">READ</a>
Do you have any idea how I could do it?
Thanks for the reply.
Hi,
a Shortcode should still work here, you would then just pass the ROW
number as a parameter:
add_shortcode( 'directory-url-row', 'shortcode_0cg0_directory_url_row' );
function shortcode_0cg0_directory_url_row( $atts ) {
$row = (int) $atts['row'];
$url = '/directory/' . $_GET['xyz'] . '?test=' . $row;
return '<a href="' . esc_url( $url ) . '">READ</a>';
}
(Note that passing ENT_QUOTES
to esc_url()
will not work (and actually might trigger an error.)
Then, you can use this in the cells:
=[directory-url-row row={ROW}]
Regards,
Tobias
Thread Starter
0cg0
(@0cg0)
Great Tobias,
it works very well.
It seems more solid to me than the Javascript solution.
I’ll do some in-depth testing tomorrow.
Thanks again, you are always very kind.
Greetings
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!