Hi Charles,
Have you seen this section in the documentation:
https://wpdataaccess.com/docs/documentation/data-explorer/table-and-view-settings/#examples-of-dynamic-hyperlinks
Please keep in mind:
(1) When the content of your dynamic hyperlink starts with plain text, the plugin will put your content in an a tag
(2) When the content of your dynamic hyperlink starts with a html tag or #macro, the plugin will only substitute values and execute macros
If you want to add javascript to a dynamic hyperlink, make sure the content of your hyperlink starts with a html tag. After that you can add a function call to your hyperlink like this:
<a href="javascript:void(0)" onclick="addItemToCart('$$id$$')">$$text$$</a>
You can add function addItemToCart to your page with the Code Manager. Just like you suggested for the Data Publisher! ??
This is the simplest solution from my perspective, but you can do this with php as well. ?? Please see the documentation for filter wpda_column_default:
https://wpdataaccess.com/2020/01/29/filter-wpda_column_default-to-influence-column-layout-in-list-table/
Filter wpda_column_default is executed for every row/column and allows you to overwrite column content. You can still use a dynamic hyperlink and overwrite that column. But you could add your hyperlink to an existing column as well. You can use any column value in your content with: $item['column_name']
For column is this would be: $item['id']
For your dynamic hyperlink: $item['wpda_hyperlink_0']
Where wpda_hyperlink_0 represents the first dynamic hyperlink of your table. Here is the same examples with a filter:
function my_column_default(
$value,
$item,
$column_name,
$table_name,
$schema_name,
$wpda_list_columns,
$list_number,
$self
) {
if ( 'wpda_hyperlink_0' === $column_name ) {
return '<a href="javascript:void(0)" onclick="addItemToCart(\'" + $item['id'] + "\')">' . $item['text'] . '</a>';
}
return $value;
}
add_filter( 'wpda_column_default' , 'my_column_default' , 10 , 8 );
Make sure the code is executed only for the table involved. To prevent the filter is execute for every column on every page, you might consider to add this filter only when needed.
Does this help?
Best regards,
Peter