javascript - Datatable with several input options
问题描述
My goal is: I would like to use datatable with multiple filtering options. for this purpose all files should be separated from each other (means that there is an html, js, php file) and read from a database. however, with my current code in js i get the error message:
ReferenceError: $ is not defined
I'm new in this area, could someone have found a suitable manual for my application? everything on the internet has been coded into one or two files. I use also smarty.
My Files:
test.php
<?php
require_once './Smarty/libs/Smarty.class.php';
echo "<script src=\"javascripts/test.js?v=3\" type=\"text/javascript\"></script>";
echo "<script src=\"javascripts/jquery.js?v=3\" type=\"text/javascript\"></script>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css\">";
$smarty = new Smarty();
$smarty->display('test.tpl');
test.js
$(document).ready(function() {
$('#datatables-table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "testHelper.php?action=listmovies",
type: "post",
datafilter: function(data){
var json = jQuery.parseJSON(data);
if (json.error){
console.log(json.error);
}
}
},
columns: [
{"data": "test", "name": "test", "title": "Test"},
{"data": "test2", "name": "test2", "title": "Test2"},
]
});
} );
test.tpl
<main class="content">
<table id="datatables-table" class="table table-striped table-hover" style="width:100%"></table>
</main>
testHelper.php
<?php
if($_REQUEST['action'] == "listmovies"){
$data = array();
$value['test1'] = utf8_encode("test1");
$value['test1'] = utf8_encode("test1");
$data[] = $value;
$value2['test2'] = utf8_encode("test2");
$value2['test2'] = utf8_encode("test2");
$data[] = $value2;
$return['data'] = $data;
echo json_encode($return);
}
解决方案
推荐阅读
- go - 确定 go.sum 中为什么存在每一行
- visual-studio-code - 将多行编辑光标与 Visual Studio Code 对齐
- electron - Electron 中的 Puppeteer:错误:传递的函数不能很好地序列化
- c++ - 错误:使用系统命令行从 'int' 到 'const char*' [-fpermissive] 的无效转换
- sql-server - 为什么 SQL Server 执行计划取决于比较顺序
- python - Pandas DataFrame 在 Jupyter Notebook 中无法正确显示
- c# - 使用 IAuthorizationFilter 检查声明 - “找不到合适的类型构造函数”
- swift - 将 imageview 和背景图像组合成一个字符串
- javascript - 用于验证登录表单的 HTML/JS 脚本在提交时失败
- nginx - 从带有斜杠的 url 中删除 index.html ,web-server nginx