栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Codeigniter-如何从Ajax获取数据表数据?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Codeigniter-如何从Ajax获取数据表数据?

您可以按以下方式通过服务器端脚本执行dataTable

  1. 更改控制器,使其可以处理数据表中的服务器端调用,并且只能在控制器中创建动态链接。我在控制器中添加了注释,以获取更多详细信息。
  2. 更改脚本以使用ajax调用它。
  3. 加载页面时,请勿在视图tbody中加载任何内容。
  4. 注意:我已跳过直接查询使用的模型部分。希望您可以更改它。

控制器

public function index() {        $data = array();        if ($this->input->is_ajax_request()) {   $search = $this->input->get('search'); $offset = $this->input->get('start'); $limit = $this->input->get('length'); $order = $this->input->get('order'); $column = array('parameter', 'method', 'type'); $orderColumn = isset($order[0]['column']) ? $column[$order[0]['column']] : 'parameter'; $orderDirection = isset($order[0]['dir']) ? $order[0]['dir'] : 'asc'; $ordrBy = $orderColumn . " " . $orderDirection; if (isset($search['value']) && !empty($search['value'])) {                    $sql = "SELECt * FROM TABLE_NAME WHERe column_name '%like%'" . $search['value'] . " order by " . $ordrBy . " limit $offset,$limit";     $sql = "SELECt count(*) FROM TABLE_NAME WHERe column_name '%like%'" . $search['value'] . " order by " . $ordrBy;     $result = $this->db->query($sql);     $result2 = $this->db->query($sql2);     $count = $result2->num_rows(); } else {          $sql = "SELECt * FROM TABLE_NAME  order by " . $ordrBy . " limit $offset,$limit";     $sql2 = "SELECt * FROM TABLE_NAME  order by " . $ordrBy;     $result = $this->db->query($sql);     $result2 = $this->db->query($sql2);     $count = $result2->num_rows(); }  $data = array(); if (!empty($result->result())) {     foreach ($result->result() as $k => $v) {         $data[] = array(     'parameter' =>  "<a href=".set_url('parameter/parameter_view/'.$v['parameter_ID'])."><strong>".$v['parameter_name']."</strong></a>",    'method' =>  "<a href=".set_url('parameter/parameter_view/'.$v['parameter_ID'])."><strong>".$v['parameter_name']."</strong></a>",    'parameter_type' =>  "<a href=".set_url('parameter/parameter_view/'.$v['parameter_ID'])."><strong>".$v['parameter_name']."</strong></a>",    'actions' =>  "<a href=".set_url('parameter/parameter_view/'.$v['parameter_ID'])."><strong>".$v['parameter_name']."</strong></a>"         );     } }  $results = array(     "draw" => $this->input->get('draw'),     "recordsTotal" => count($data),     "recordsFiltered" => $count,     "data" => $data  ); echo json_enpre($results);        } else {  $this->site->view('parameter', $data);        }    }

视图

   <table id="parameter" >  <thead>    <tr>      <th >Parameter</th>      <th >Method</th>      <th >Type</th>      <th >Action</th>    </tr>  </thead>  <tbody>      </tbody>  <tfoot>    <tr>      <th >Parameter</th>      <th >Method</th>      <th >Type</th>      <th >Action</th>    </tr>  </tfoot></table>

脚本

 <script>        $(document).ready(function() { $('#example').DataTable({     url: '<?php base_url(); ?>controllerName/index',     processing: true,     serverSide: true,     paging: true,     searching: true,     ordering: true,     order: [[0, "asc"]],     scrollX: true,     scroller: true,     columns: [{data: "parameter"}, {data: "method"}, {data: "parameter_type"}, {data: "action"}]      });        });    </script>

如果您想使用某些第三方库,请选中此选项。为了您的型号查询,你可以自定义在提这个职位。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/401744.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号