点燃数据表搜索不使用服务器端处理

时间:2014-08-21 11:57:29

标签: php codeigniter datatables

数据显示正常,但搜索过滤器无效。 我使用Codeigniter和Ignited Datatables。

这是我可能会说的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 Library Function,它似乎有问题

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 Parameters

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中,它正在寻找搜索

Ignited Datatables library,get_filtering function。     $ search = $ this-&gt; ci-&gt; input-&gt; post(&#39; search&#39;);

所以我尝试将其更改为

$search = $this->ci->input->post('sSearch');
之后,我的数据表甚至阻止了我显示之前显示的数据。所以我不得不反向搜索..

如果有人有任何专业知识,请解释一下我在这里做错了什么。

2 个答案:

答案 0 :(得分:3)

使用了错误的点燃dataTables库。

似乎不同用户在github上有两个版本的被点燃的DataTables库。

使用下面的库完全符合我的dataTable发送给服务器的参数。

https://github.com/cryogenix/Ignited-Datatables/blob/master/application/libraries/Datatables.php

答案 1 :(得分:0)

我试图实现点火器表,甚至在意识到我使用了错误的库之后,我的表只是加载 - 永远 - 但数据没有出现。我正在开发使用'开发'环境_在我耳边低声说话的东西(也许是魔鬼)并且告诉我在生产环境中测试它并且有效,它有效!我是CI的新手,我不知道为什么会这样。