【发布时间】:2014-10-15 01:16:54
【问题描述】:
数据显示正常,但搜索过滤器不起作用。 我将 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]);
}
现在终于发布参数了
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,但在 ignitedDatables 中,它正在寻找搜索
点燃的数据表库,get_filtering 函数。 $search = $this->ci->input->post('search');
所以我尝试将其更改为
$search = $this->ci->input->post('sSearch');
在那之后,我的数据表甚至阻止我显示它之前显示的数据。所以我不得不倒退搜索..
如果有人有任何专业知识,请解释我在这里做错了什么。
【问题讨论】:
标签: php codeigniter datatables