Support Forum
Support › MB Custom Table › Custom Model needs additional hooks please
Hi guys,
We're loving the new Custom Model capability, a huge leap forwards for WP!
I appreciate that this is a very new feature for MB Custom Table but in trying to use it for the first time on a new client project we are coming up against some significant limitations. All the basic functionality is there but when you want to add content using standard WP hooks we find they don't exist (or at least not in a way we can find out).
Please could you add the following capabilities to the ListTable class for Custom Table?
1. extra_tablenav - So we can add custom filters for the table. Possibly as follows...
/**
* @param string $which
*/
protected function extra_tablenav( $which ) {
?>
<div class="alignleft actions">
<?php
if ( 'top' === $which ) {
ob_start();
do_action( 'restrict_manage_posts', $this->model->name, $which );
$output = ob_get_clean();
if ( ! empty( $output ) ) {
echo $output;
submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
}
}
?>
</div>
<?php
}
2. list_table_primary_column - So we can define a primary column for the table (that contains the row actions) to replace the currently hard-coded id column.
3. Row Actions - So we can hook into and add/edit/delete row actions for custom functionality.
4. In a perfect world... - We'd love to be able to hook into (and modify) the html created for the each of the table headers as we would like to be able to create an individual column search capability.
In short, please can you add in the List table hooks that we are used to being able to use for a standard CPT.
Thanks in advance guys.
All the best,
Will
Sorry, I know I bombarding you...
Could you also add in some form of confirmation before items are deleted?
A modification of the list-table.js to something like this would be perfect.
// Delete an item.
$( document ).on( 'click', '.row-actions .delete a', function( e ) {
e.preventDefault();
if (confirm('Are you sure you want to delete this item? This action cannot be undone.')) { // Add this in
const $this = $( this );
$.post( ajaxurl, {
action: 'mbct_delete_items',
ids: [ parseInt( $this.data( 'id' ), 10 ) ],
model: $( 'input[name="model"]' ).val(),
_ajax_nonce: MbctListTable.nonceDelete,
}, response => {
if ( response.success ) {
$this.closest( 'tr' ).css( 'background', '#ff8383' ).hide( 'slow', function() {
$( this ).remove();
} );
} else {
alert( response.data );
}
} );
}
} );
Hi,
Thanks for your suggestion.
I will forward these to the development team to consider adding them to the plugin in future updates.
Thanks as always Long. Here's hoping they make it into the next release 🙂
One more request for the dev team if you can face it... 🙂
It would be great to be able to target the various MB Custom Table admin views in CSS. Currently each screen in the admin area has the same body classes. In standard WordPress CPTs you can target classes such as 'edit-php' or 'post-php' to differentiate between a List Table view, or an Add or Edit one.
Thanks in advance,
Will
Hi,
Any update on getting the following protection put in place? As there is no 'bin' when using a custom model we need to protect clients from accidentally deleting records
https://support.metabox.io/topic/custom-model-needs-additional-hooks-please/#post-31094
Thanks in advance.
Will
Hi Will,
It would be great to be able to target the various MB Custom Table admin views in CSS. Currently each screen in the admin area has the same body classes. In standard WordPress CPTs you can target classes such as 'edit-php' or 'post-php' to differentiate between a List Table view, or an Add or Edit one.
Thank you for your feedback.
I'm going to inform the developer team to consider adding it to the to-do list for the future development of the plugin.
Any update on getting the following protection put in place? As there is no 'bin' when using a custom model we need to protect clients from accidentally deleting records
This feature will be included in the next update.
Thanks Long, really appreciate it.
Cheers,
Will