-
-
Save reachkamrul/d2dd323dde5c5508de46eab7dc0337a7 to your computer and use it in GitHub Desktop.
Show Ninja Tables On Admin settings Page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* By Default Ninja Tables does not work if you want to render table on | |
* admim panel. The following code will create a top level admin page and render a table | |
* the example table if is 1306 that you need to change | |
*/ | |
add_action( 'admin_menu', function () { | |
add_menu_page( 'Admin View', 'NT Admin', 'manage_options', 'myplugin/myplugin-admin-page.php', function () { | |
$tableId = 1306; // 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>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment