【问题标题】:ignited datatables search not working with server side processing点燃的数据表搜索不适用于服务器端处理
【发布时间】: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


    【解决方案1】:

    使用了错误的 ignited dataTables 库。

    似乎github上有两个不同用户的ignited DataTables库版本。

    使用下面这个库完全符合我的数据表发送到服务器的参数。

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

    【讨论】:

      【解决方案2】:

      我试图实现点火器表,即使在意识到我使用了错误的库之后,我的表只是加载 - 永远 - 但数据没有出现。我正在使用“开发”环境进行开发 _ 在我耳边窃窃私语(也许是魔鬼)并告诉我在生产环境中测试它,瞧,它奏效了!我是 CI 新手,不知道为什么会这样。

      【讨论】:

      • 上瘾了,我改变了我的 index.php 以至少看到错误。定义(“环境”,“生产”); case 'testing': case 'production': //而不是这个 //error_reporting(0); //ini_set("display_errors", 0); //
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 2015-03-11
      • 2018-05-16
      • 1970-01-01
      • 2014-10-06
      相关资源
      最近更新 更多