Mysql 如何用datatable解决Codeigniter中的搜索
我在标签搜索中遇到问题,当我键入某个字符时,它会显示错误消息 我的控制器:Mysql 如何用datatable解决Codeigniter中的搜索,mysql,codeigniter,datatables,codeigniter-2,codeigniter-3,Mysql,Codeigniter,Datatables,Codeigniter 2,Codeigniter 3,我在标签搜索中遇到问题,当我键入某个字符时,它会显示错误消息 我的控制器: public function ajaxlist() { $list = $this->eee_model->get_datatables(); $data = array(); $no=0; foreach ($list as $q) { $no++; $row = array(); $row[] = $no;
public function ajaxlist()
{
$list = $this->eee_model->get_datatables();
$data = array();
$no=0;
foreach ($list as $q) {
$no++;
$row = array();
$row[] = $no;
$row[] = $q->nofile;
$row[] = $q->est_no ."/".$q->file_no;
$row[] = $q->number;
$row[] = $q->nobilut;
$row[] = $q->nounit;
$row[] = $q->zone;
$row[] = $q->subz;
$row[] = '<a class="btn btn-sm btn-primary" href="'.site_url($q->file).'" "><i class="fa fa-file-pdf-o"></i></a>';
$row[] = '<a class="btn btn-sm btn-primary" href="'.site_url("estebyan/edit/".$q->id).'" title="Edit" target="_blank" "><i class="fa fa-edit"></i> edit</a>';
$row[] = '<a class="btn btn-sm btn-danger" href="javascript:void(0)" title="Hapus" onclick="delete_person('."'".$q->id."'".')"><i class="fa fa-trash"></i> delete</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->estebyan_model->count_all(),
"recordsFiltered" => $this->estebyan_model->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
我的看法是:
<table id="table" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>#</th>
<th>nofile</th>
<th>fileno</th>
<th>number</th>
<th>nobulit</th>
<th>unit</th>
<th>Zone</th>
<th>Sub</th>
<th>attach</th>
<th >edit</th>
<th >delete</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
#
nofile
文件描述符
数
贵族
单位
区
附属的
贴上
编辑
删除
我的剧本:
table = $('#table').DataTable({
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo site_url('estebyan/ajaxlist')?>",
"type": "POST"
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ 0 ], //first column / numbering column
"orderable": false, //set not orderable
},
],
});
table=$('#table')。数据表({
“处理”:true,//特性控制处理指示器。
“服务器端”:true,//功能控制数据表的服务器端处理模式。
“订单”:[],//初始无订单。
//从Ajax源加载表内容的数据
“ajax”:{
“url”:“,
“类型”:“职位”
},
//设置列定义初始化属性。
“columnDefs”:[
{
“目标”:[0],//第一列/编号列
“可订购”:false,//设置为不可订购
},
],
});
显示所有视图数据,但搜索不起作用 $.ajax({
$.ajax({
type: "post",
url: "your url",
dataType: "json",
success: function(data){ // return json encode data
if(data.length > 0){
tabledata = [];
for (var i = 0; i < data.length; i++) {
tabledata.push([ // push data in array as per your column
data[i].name,
data[i].other_value,
data.[i].other_value]);
}
if (table != null) table.fnDestroy();
table = $('#tablename').dataTable({
"data": tabledata, // add your data array it will create datatable with search and pagination and other things
});
}
},
error: function(){
}
});
类型:“post”,
url:“您的url”,
数据类型:“json”,
成功:函数(数据){//返回json编码数据
如果(data.length>0){
tabledata=[];
对于(变量i=0;i
如果您没有datatable.js和datatable.css,请先包含并尝试此代码如果您的datatables\u查询中的order数组中没有任何内容,请在处理订单之前尝试编写此代码
$column\u order=$this->column\u order代码>
$.ajax({
type: "post",
url: "your url",
dataType: "json",
success: function(data){ // return json encode data
if(data.length > 0){
tabledata = [];
for (var i = 0; i < data.length; i++) {
tabledata.push([ // push data in array as per your column
data[i].name,
data[i].other_value,
data.[i].other_value]);
}
if (table != null) table.fnDestroy();
table = $('#tablename').dataTable({
"data": tabledata, // add your data array it will create datatable with search and pagination and other things
});
}
},
error: function(){
}
});