I am trying to integrate jQuery Datables into my Wordpress plugin http://editor.datatables.net/
I have Created a database table
CREATE TABLE `id` (
`id` int(10) NOT NULL auto_increment,
`first` varchar(255) default NULL,
`last` varchar(255) default NULL,
`age` varchar(255) default NULL,
PRIMARY KEY (`id`)
);
I have enqueued the required files
$this->enqueueStyle(
dirname( APFDEMO_FILE ) . '/datatables/css/demo.css',
'apf_first_page' // page slug
);
$this->enqueueStyle(
dirname( APFDEMO_FILE ) . '/datatables/css/jquery.dataTables.css',
'apf_first_page' // page slug
);
$this->enqueueStyle(
dirname( APFDEMO_FILE ) . '/datatables/css/dataTables.tableTools.css',
'apf_first_page' // page slug
);
$this->enqueueStyle(
dirname( APFDEMO_FILE ) . '/datatables/css/dataTables.editor.css',
'apf_first_page' // page slug
);
$this->enqueueScript(
dirname( APFDEMO_FILE ) . '/datatables/js/jquery.dataTables.min.js', // source url or path
'apf_first_page', // page slug
'', // tab slug
array(
'handle_id' => 'my_dataTables_script', // this handle ID also is used as the object name for the translation array below.
)
);
$this->enqueueScript(
dirname( APFDEMO_FILE ) . '/datatables/js/dataTables.tableTools.min.js', // source url or path
'apf_first_page', // page slug
'', // tab slug
array(
'handle_id' => 'my_dataTablesTool_script', // this handle ID also is used as the object name for the translation array below.
)
);
$this->enqueueScript(
dirname( APFDEMO_FILE ) . '/datatables/js/dataTables.editor.js', // source url or path
'apf_first_page', // page slug
'', // tab slug
array(
'handle_id' => 'my_dataTableseditor_script', // this handle ID also is used as the object name for the translation array below.
)
);
I have declared the datatables and the html for the table
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
"ajax": "admin-ajax.php?action=datatables",
"table": "#id",
"fields": [
{
"label": "first",
"name": "first",
"type": "text"
},
{
"label": "last",
"name": "last",
"type": "text"
},
{
"label": "age",
"name": "age",
"type": "text"
}
]
} );
$('#id').dataTable( {
"dom": "Tfrtip",
"ajax": "admin-ajax.php?action=datatables",
"columns": [
{
"data": "first"
},
{
"data": "last"
},
{
"data": "age"
}
],
"tableTools": {
"sRowSelect": "os",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
} );
<div class="container">
<h1>DataTables Editor - id</h1>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="id" width="100%">
<thead>
<tr>
<th>first</th>
<th>last</th>
<th>age</th>
</tr>
</thead>
</table>
</div>
Declared the ajax functions
add_action( 'wp_ajax_datatables', 'my_datatables_callback' );
function my_datatables_callback() {
include( APFDEMO_DIRNAME . '/datatables/php/table.id.php' );
die();
}
I can get the tables to properly load up in the plugin's page but When i try to edit/create/update it doesn't do anything.
Does anyone have experience integrating datatables into wordpress plugin.
I think the main problem is at
var editor = new $.fn.dataTable.Editor( {
"ajax": "admin-ajax.php?action=datatables",
would be really helpful
Thanks.