I try to include my original button to rendered page by a shortcode of [cdbt-view].
For example if table is as follows:
CREATE TABLE wp_int_test (
ID int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
col int(11) NOT NULL,
created datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'created datetime',
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'updated datetime',
PRIMARY KEY (ID)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
The html contents in body of post is follows:
[cdbt-view table="wp_int_test" display_search="false" display_list_num="false" enable_sort="false" exclude_cols="created"]
<script>
function refresh_page() {
location.reload();
}
</script>
In the “templates/cdbt-public-list.php” on the directory of cdbt plugin, I have customized as follows:
# 189 to 190 lines
$output = apply_filters('cdbt_view_column_value', $val, $table_name, $key);
$list_rows .= '<td>'. $output .'</td>';
Then, In the “functions.php” of using theme, I have added as follows:
add_filter('cdbt_view_column_value', 'add_my_button', 10, 4);
function add_my_button($val, $table_name, $column_name, $id) {
if ($table_name == 'wp_int_test' && $column_name == 'col') {
$increase_query = sprintf('UPDATE %s SET %s = %d WHERE ID = %d', $table_name, $column_name, intval($val)+1, intval($id));
$increase_button = do_shortcode(sprintf('[cdbt-submit table="%s" label="%s" query="%s" final="refresh_page" add_class="%s"]', $table_name, '+', $increase_query, 'default btn-xs'));
$decrease_query = sprintf('UPDATE %s SET %s = %d WHERE ID = %d', $table_name, $column_name, intval($val)-1, intval($id));
$decrease_button = do_shortcode(sprintf('[cdbt-submit table="%s" label="%s" query="%s" final="refresh_page" add_class="%s"]', $table_name, '-', $decrease_query, 'default btn-xs align-left'));
$val = sprintf('%s <p class="pull-right">%s%s</p>', $val, $increase_button, $decrease_button);
}
return $val;
}
By the above as, you can make a list of pages that you can change the value by added buttons of “+” or “-” to the particular column.
Screenshot image of the sample is here.