Using jQuery jTable with WordPress Plugin in Admin Menu Area

Wanting to get (and add/edit) records from the DB using jQuery-jTable plugin (jtable.org). I’ve enqueued the scripts needed and verified that they are loading via the page source but I don’t get anything. According to the getting started guide I should at least get a blank table but I get a blank page. My code is below — any ideas?

Code to enqueue scripts:

Read More
function lfc_load_scripts() {
//set global variables
global $plugin_url;

//set variable to use to point to process.php path
$js_vars = array('plugin_url'=>$plugin_url,);

//Load scripts and css for Tabs UI
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('lfc-ui-js', $plugin_url . 'includes/js/tabs-ui.js', array('jquery'));
wp_localize_script( 'lfc-ui-js', 'js_vars', $js_vars) ;
wp_register_style( 'lfc_jquery_admin_css', $plugin_url . 'includes/css/ui.css', false, '1.0.0' );
    wp_enqueue_style( 'lfc_jquery_admin_css' );

//Load scripts and css for jTable
    wp_enqueue_script('jquery-ui-core');
    wp_enqueue_script('lfc-jtable-js', $plugin_url . 'includes/js/jtable/jquery.jtable.js', array('jquery'));
wp_register_style( 'lfc_jtable_css', $plugin_url . 'includes/js/jtable/themes/metro/blue/jtable.css', false, '1.0.0' );
    wp_enqueue_style( 'lfc_jtable_css' );

    //Load main jQuery file
wp_enqueue_script('lfc-process-js', $plugin_url . 'includes/js/process.js', array('jquery'));

}
add_action('admin_enqueue_scripts', 'lfc_load_scripts');

And this is the jQuery (as per the instructions on the jTable.org page)

$('#FighterTableContainer').jtable({
        title: 'Table of people',
        actions: {
            listAction: '/GettingStarted/PersonList',
            createAction: '/GettingStarted/CreatePerson',
            updateAction: '/GettingStarted/UpdatePerson',
            deleteAction: '/GettingStarted/DeletePerson'
        },            
        fields: {
            PersonId: {
                key: true,
                list: false
            },
            Name: {
                title: 'Author Name',
                width: '40%'
            },
            Age: {
                title: 'Age',
                width: '20%'
            },
            RecordDate: {
                title: 'Record date',
                width: '30%',
                type: 'date',
                create: false,
                edit: false
            }
        }
});

Related posts

Leave a Reply

1 comment

  1. I’ve tested jTable in a dummy plugin and it worked showing a blank table with the declared fields (Name, Age and RecordDate).

    Issues with your code:

    1) The following:

    wp_enqueue_script( 'jquery-ui-tabs' );
    wp_enqueue_script( 'lfc-ui-js', $plugin_url . 'includes/js/tabs-ui.js', array('jquery'));
    

    Can be declared as:

    wp_enqueue_script(
        'lfc-ui-js', 
        $plugin_url . 'includes/js/tabs-ui.js', 
        array( 'jquery', 'jquery-ui-tabs' ) 
    );
    

    And the same for the script 'lfc-jtable-js'. Maybe, the one with your code need to be enqueued on footer.

    2) Wrap your code with (document).ready, like so:

    jQuery(document).ready(function($) {   
        $('#FighterTableContainer').jtable({
            // rest of the code
        });
    });