Skip to content

Instantly share code, notes, and snippets.

@ahsannayem
Last active September 27, 2023 06:01
Show Gist options
  • Save ahsannayem/4e6097bb6c5398f3dc2b1e127d4b8cdb to your computer and use it in GitHub Desktop.
Save ahsannayem/4e6097bb6c5398f3dc2b1e127d4b8cdb to your computer and use it in GitHub Desktop.
Show table on the WordPress Deshboard
add_action( 'admin_menu', function () {
add_menu_page( 'Admin View', 'NT Admin', 'manage_options', 'myplugin/myplugin-admin-page.php', function () {
$tableId = 173; // This is ninja table ID;
ninjaRenderTableOnAdmin($tableId);
}, 'dashicons-tickets', 6 );
} );
// Global function to render a table in admin panel
function ninjaRenderTableOnAdmin($tableId)
{
add_action('ninja_table_before_render_table_source', function ($table, $table_vars, $tableArray) {
add_action('admin_footer', function () use ($table_vars, $tableArray) {
?>
<script type="text/javascript">
window['<?php echo $table_vars['instance_name'];?>'] = <?php echo json_encode($table_vars, true); ?>
</script>
<?php
});
}, 10, 3);
echo "<div style='background: white;' class='ninja_table_admin_wrap wrap'>";
echo do_shortcode('[ninja_tables id="'.$tableId.'"]');
echo '</div>';
}
@ahsannayem
Copy link
Author

Add the following code and make sure you have changed the table ID.

add_action( 'admin_menu', function () {
add_menu_page( 'Admin View', 'NT Admin', 'manage_options', 'myplugin/myplugin-admin-page.php', function () {
$tableId = 65; // This is ninja table ID;
ninjaRenderTableOnAdmin($tableId);
}, 'dashicons-tickets', 6 );

add_submenu_page(
'myplugin/myplugin-admin-page.php',
'Second Table',
'Second Table',
'manage_options',
'myplugin-admin-page.php',
function () {
$id = 66; // This is ninja table ID;
ninjaRenderTableOnAdmin($id);
}
);

} );

// Global function to render a table in admin panel
function ninjaRenderTableOnAdmin($tableId)
{
add_action('ninja_table_before_render_table_source', function ($table, $table_vars, $tableArray) {
add_action('admin_footer', function () use ($table_vars, $tableArray) {
?>
<script type="text/javascript">
window[''] =
</script>
<?php
});
}, 10, 3);
echo "

";
echo do_shortcode('[ninja_tables id="'.$tableId.'"]');
echo '
';
}

@bewj
Copy link

bewj commented Sep 26, 2023 via email

@ahsannayem
Copy link
Author

Certainly! Please feel free to contact me via email at ahsanchowdhurynayem@gmail.com and provide me with all the necessary details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment