数据显示良好,但搜索过滤器不工作。我使用Codeigniter与点燃的数据表。
这是我的HTML代码或视图文件。
<table id="ManageForms" class="table table-bordered table-condensed table-hover table-striped">
<thead>
<tr>
<th>Form Name</th>
<th>Form Path</th>
<th>Form CI Path</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
$(document).ready(function() {
$('#ManageForms').dataTable({
"bServerSide":true,
"bProcessing":true,
"sPaginationType": "full_numbers",
"bFilter":true,
"sServerMethod": "POST",
"sAjaxSource": "{{base_url()}}admin/configurations/listForms_DT/",
"iDisplayLength": 2,
"aLengthMenu": [[2, 25, 50, -1], [2, 25, 50, "All"]],
"sEcho": 1,
"columns":[
{data:"FormName"},
{data:"FormPath"},
{data:"FormCIPath"},
{ "data": null,
"defaultContent": "<button>Edit</button>",
"targets": -1
}
],
'fnServerData' : function(sSource, aoData, fnCallback){
$.ajax ({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
}); //end of ajax
}
});
} );
</script>
控制器:
function listForms_DT(){
$this->datatables->select('FormID, FormName, FormPath, FormCIPath')
->unset_column('FormID')
->from('sys_forms');
echo $this->datatables->generate();
}//end of list_forms_view
}
引燃的数据表库函数,它似乎有问题
public function generate($output = 'json', $charset = 'UTF-8')
{
if(strtolower($output) == 'json')
$this->get_paging();
$this->get_ordering();
$this->get_filtering();
return $this->produce_output(strtolower($output), strtolower($charset));
}
/**
* Generates the LIMIT portion of the query
*
* @return mixed
*/
private function get_paging()
{
$iStart = $this->ci->input->post('iDisplayStart');
$iLength = $this->ci->input->post('iDisplayLength');
if($iLength != '' && $iLength != '-1')
$this->ci->db->limit($iLength, ($iStart)? $iStart : 0);
}
/**
* Generates the ORDER BY portion of the query
*
* @return mixed
*/
private function get_ordering()
{
$Data = $this->ci->input->post('columns');
if ($this->ci->input->post('order'))
foreach ($this->ci->input->post('order') as $key)
if($this->check_cType())
$this->ci->db->order_by($Data[$key['column']]['data'], $key['dir']);
else
$this->ci->db->order_by($this->columns[$key['column']] , $key['dir']);
}
/**
* Generates a %LIKE% portion of the query
*
* @return mixed
*/
private function get_filtering()
{
$mColArray = $this->ci->input->post('iColumns');
$sWhere = '';
$search = $this->ci->input->post('search');
$sSearch = $this->ci->db->escape_like_str(trim($search['value']));
$columns = array_values(array_diff($this->columns, $this->unset_columns));
if($sSearch != '' && $sSearch != 0)
for($i = 0; $i < count($mColArray); $i++)
if($mColArray[$i]['searchable'] == 'true' )
if($this->check_cType())
$sWhere .= $this->select[$mColArray[$i]['data']] . " LIKE '%" . $sSearch . "%' OR ";
else
$sWhere .= $this->select[$this->columns[$i]] . " LIKE '%" . $sSearch . "%' OR ";
$sWhere = substr_replace($sWhere, '', -3);
if($sWhere != '')
$this->ci->db->where('(' . $sWhere . ')');
// TODO : sRangeSeparator
foreach($this->filter as $val)
$this->ci->db->where($val[0], $val[1], $val[2]);
}
最后是Post参数
bRegex false
bRegex_0 false
bRegex_1 false
bRegex_2 false
bRegex_3 false
bSearchable_0 true
bSearchable_1 true
bSearchable_2 true
bSearchable_3 true
bSortable_0 true
bSortable_1 true
bSortable_2 true
bSortable_3 true
iColumns 4
iDisplayLength 2
iDisplayStart 0
iSortCol_0 0
iSortingCols 1
mDataProp_0 FormName
mDataProp_1 FormPath
mDataProp_2 FormCIPath
mDataProp_3
sColumns ,,,
sEcho 1
sSearch
sSearch_0
sSearch_1
sSearch_2
sSearch_3
sSortDir_0 asc
在我看来,问题是我的数据表是张贴sSearch,但在点燃的数据表,它正在寻找搜索
点火表库,get_filtering函数。$search = $this->ci->input->post('search');
所以我试着把它改成$search = $this->ci->input->post('sSearch');
之后,我的数据表甚至停止显示它之前显示的数据。所以我不得不返回搜索…
如果有人有任何专业知识,请解释一下我在这里做错了什么
使用了错误的点燃的数据库库。
似乎github上有两个不同用户的版本。
使用下面的库完全符合我的dataTables发送给服务器的参数。
https://github.com/cryogenix/Ignited-Datatables/blob/master/application/libraries/Datatables.php
我试图实现点火器表,甚至在意识到我使用了错误的库之后,我的表只是加载-永远-但数据没有出现。我正在使用"开发"环境进行开发——在我耳边低语(可能是魔鬼),并对我说,在生产环境中测试它,瞧,它成功了!我是CI的新手,我不知道为什么会发生这种情况