我正在尝试将jQuery数据库集成到我的Wordpress插件中http://editor.datatables.net/
我已经创建了一个数据库表
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`)
);
我已将所需文件排入队列
$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.
)
);
我已经为表声明了datatables和html
$(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>
声明了ajax函数
add_action( \'wp_ajax_datatables\', \'my_datatables_callback\' );
function my_datatables_callback() {
include( APFDEMO_DIRNAME . \'/datatables/php/table.id.php\' );
die();
}
我可以让这些表在插件的页面中正确加载,但当我尝试编辑/创建/更新时,它不会做任何事情。
有没有人有将数据表集成到wordpress插件的经验。
我认为主要问题在于
var editor = new $.fn.dataTable.Editor( {
"ajax": "admin-ajax.php?action=datatables",
真的很有帮助
谢谢