[英]ignited datatables search not working with server side processing
數據顯示正常,但搜索過濾器不起作用。 我使用帶有點火數據表的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
}
Ignited Datatables庫函數,似乎有問題
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,但在ignitedDatables中,它正在尋找搜索
點火的數據表庫,get_filtering函數。 $ search = $ this-> ci-> input-> post('search');
所以我嘗試將其更改為
$search = $this->ci->input->post('sSearch');
之后,我的數據表甚至使我無法顯示以前顯示的數據。 所以我不得不退回去搜索。
如果有人有專業知識,請告訴我我在做什么錯。
使用了錯誤的點火數據表庫。
看來github上有兩個版本的被點燃的DataTables庫,都是由不同的用戶使用的。
使用下面的這個庫完全適合我的dataTables發送到服務器的參數。
https://github.com/cryogenix/Ignited-Datatables/blob/master/application/libraries/Datatables.php
我試圖實現點火器表,甚至在意識到我使用了錯誤的庫之后,我的表仍被永久加載,但數據並未出現。 我正在使用“開發”環境進行開發-某些東西在我耳邊低語(也許是魔鬼),並說要在生產環境中測試它,這確實有效! 我是CI的新手,我不知道為什么會這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.