Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 动态自定义过滤器在codeigniter中不工作_Jquery_Ajax_Codeigniter_Datatables - Fatal编程技术网

Jquery 动态自定义过滤器在codeigniter中不工作

Jquery 动态自定义过滤器在codeigniter中不工作,jquery,ajax,codeigniter,datatables,Jquery,Ajax,Codeigniter,Datatables,我有一个带有自定义过滤器和数据表的codeigniter表单。我正在使用jquery、ajax加载数据。我所期望的是,例如,当我选择公司列表时,我只希望选择在数据表中加载的公司。但是现在发生的是datatables中的所有数据加载,就好像没有过滤器一样。请帮忙 谢谢 这是我的控制器 <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Assetfilter extends CI_

我有一个带有自定义过滤器和数据表的codeigniter表单。我正在使用jquery、ajax加载数据。我所期望的是,例如,当我选择公司列表时,我只希望选择在数据表中加载的公司。但是现在发生的是datatables中的所有数据加载,就好像没有过滤器一样。请帮忙

谢谢

这是我的控制器

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

 class Assetfilter extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        $this->load->model('user');
        $this->load->model('assetfiltermdl');
        $this->load->model('worklistmdl');
        $this->load->helper('url'); 
        $this->load->helper('date');
        $this->load->library('session');
        $this->load->library('email');
        $this->load->model('email_ctrl');
        $this->datauser = $this->session->userdata('logged_id');
        $this->load->library('form_validation');
        $this->load->library('My_PHPMailer');
        //Do your magic here
    }

    //update 20 oct 2016 list kary.

    public function kary_reload()
    {
        $list = $this->assetfiltermdl->get_listkary();
        $data = array();
        $no = $_POST['start'];
        foreach ($list as $listkary) {
            $no++;
            $row = array();
            $row[] = trim($listkary->idnik) . " ";
            $row[] = trim($listkary->kodenik). " ";
            $row[] =  rtrim($listkary->namakary). " ";
            $row[] = rtrim($listkary->namaper). " ";
            $row[] = trim($listkary->iddept). " ";
            $row[] = trim($listkary->jabatan). " ";
            $row[] = trim($listkary->flagstatus). " ";
            $row[] = trim($listkary->flagstatus). " ";


            /*$row[] = '<a href="<?php echo base_url(' . "'" . 'asset/karyawandetailform' . "'" .'); ?>/<?php echo $listkary[' . "'" . 'idnik' . "'" . '] ; ?>" class="btn btn-primary"> Detail</a>
                <a href="<?php echo base_url(' . "'" . 'asset/karyawaneditform' . "'" . '); ?>/<?php echo $listkary[' . "'" . 'idnik' . "'" .'] ; ?>" class="btn btn-primary">Detail</a>
                <a href="<?php echo base_url(' . "'" . 'asset/karyawandeleform' . "'" . ');    ?>/<?php echo $listkary[' . "'" . 'idnik' . "'" .'] ; ?>" class="btn btn-primary" onClick="javascript:return confirm(' . "'" . 'Apakah Anda Sudah Yakin ?' . "'" . ')"  >Del</a>'; */

            $data[] =  ($row);
        }

        $output = array (
                        "draw" => $_POST['draw'],
                        "recordsTotal" => $this->assetfiltermdl->count_all(),
                        "recordsFiltered" => $this->assetfiltermdl->count_filtered(),
                        "data" => $data,
                );
        //output to json format

        $output = str_replace('\r'," ", $output );



        echo json_encode($output);
    }
 }

}
部门:
皮利司
}
纳玛卡里亚万
柯德尼克
滤器
重置
身份证件
柯德尼克
纳玛卡里亚万
佩鲁萨安
部门
贾巴坦
阿克提夫
行政人员
var表;
$(文档).ready(函数(){
//数据表
表=$('#master_karyawan')。数据表({
“处理”:true,//特性控制处理指示器。
“服务器端”:true,//功能控制数据表的服务器端处理模式。
“订单”:[],//初始无订单。
//从Ajax源加载表内容的数据
“ajax”:{
“url”:“,
“类型”:“职位”,
“数据”:功能(数据){
data.perush=$('#idper').val();
data.depart=$('#iddept').val();
data.namakry=$('#namakry').val();
data.kodenik=$('#kodenik').val();
}
},
//设置列定义初始化属性。
“columnDefs”:[
{ 
“目标”:[0],//第一列/编号列
“可订购”:false,//设置为不可订购
},
],
//$.fn.dataTable.ext.errMode='throw';
});
$('#btn筛选器')。单击(函数(){//按钮筛选器事件单击
table.ajax.reload(null,false);//只需重新加载表
});
$(“#btn重置”)。单击(函数(){//按钮重置事件单击
$('#表单筛选器')[0].reset();
table.ajax.reload(null,false);//只需重新加载表
});
});

可能会很晚回复,但请查看此链接,希望能解决您的问题


我希望这可以解释你的代码

可能会很晚回复,但看到这个链接希望可以解决你的问题


我希望这可以解释你的代码

“它不工作”是一个几乎毫无意义的问题陈述,特别是当你向我们展示服务器端和客户端代码时,不要孤立任何特定的东西。花几分钟回顾一下嗨,谢谢你的建议。我已经编辑了我的问题。我希望您能理解我的问题,并帮助我解决我的问题。“它不起作用”实际上是一个毫无意义的问题陈述,特别是当您向我们展示服务器端和客户端代码时,并且没有隔离任何特定的内容。花几分钟回顾一下嗨,谢谢你的建议。我已经编辑了我的问题。我希望你能理解我的问题,并帮助我解决我的问题。欢迎链接到解决方案,但请确保你的答案在没有它的情况下是有用的:这样你的其他用户就会知道它是什么以及为什么存在,然后引用你链接到的页面的最相关部分,以防目标页面不可用。如果你这么认为,删除我的信息没关系,因为我需要一个触发器给用户如果有任何问题需要进一步询问,那么我准备好解释为什么我只向她显示链接一个解决方案的链接是受欢迎的,但请确保你的答案在没有它的情况下是有用的:这样你的其他用户就会知道它是什么以及为什么它在那里,然后引用你链接到的页面最相关的部分,以防目标页面不可用。如果你这么认为,删除我的信息没关系,因为我需要一个触发器,如果用户有任何问题需要进一步询问,那么我准备解释为什么我只显示她的链接
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Assetfiltermdl extends CI_Model {

    var $kary_table = 'listkary';
    var $kary_column_order = array(null, 'update_date'); //set column field database for datatable orderable
    var $kary_column_search = array('idper','iddept','namakary','kodenik'); //set column field database for datatable searchable 
    var $kary_order = array('update_date' => 'desc'); // default order 

    public function __construct()
    {
        parent::__construct();

    }

//update 20 oct 2016

  public function get_listkary()
    {
      $this->_get_listkary_query();
      echo $this->db->last_query();
      if($_POST['length'] != -1)
      $this->db->limit($_POST['length'], $_POST['start']);
      $query = $this->db->get();
      return $query->result();
    }

  private function _get_listkary_query()
    {

      //add custom filter here
      if($this->input->post('idper'))
      {
        $this->db->where('idper', $this->input->post('idper'));
      }
      if($this->input->post('iddept'))
      {
        $this->db->where('iddept', $this->input->post('iddept'));
      }
      //if($this->input->post('idsubdept'))
      //{
      //  $this->db->like('LastName', $this->input->post('LastName'));
      //}
      if($this->input->post('kodenik'))
      {
        $this->db->like('kodenik', $this->input->post('kodenik'));
      }
      if($this->input->post('namakry'))
      {
        $this->db->like('namakary', $this->input->post('namakry'));
      }

      $this->db->from($this->kary_table);

      $i = 0;

      foreach ($this->kary_column_search as $item) // loop column 
      {
        if($_POST['search']['value']) // if datatable send POST for search
        {

          if($i===0) // first loop
          {
            $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
            $this->db->where($item, $_POST['search']['value']);
          }
          else 
          {
            if($i===1) // second loop (iddept)
            {
                $this->db->where($item, $_POST['search']['value']);
            }
            else
            {
                $this->db->like($item, $_POST['search']['value']);  
            }   
          }

          if(count($this->kary_column_search) - 1 == $i) //last loop
            $this->db->group_end(); //close bracket
        }
        $i++;
      }

      if(isset($_POST['order'])) // here order processing
        {
            $this->db->order_by($this->kary_column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
        } 
        else if(isset($this->kary_order))
        {
            $order = $this->kary_order;
            $this->db->order_by(key($order), $order[key($order)]);
        }

    }


  private function _get_listkary_count()
    {

      //add custom filter here
      if($this->input->post('idper'))
      {
        $this->db->where('idper', $this->input->post('idper'));
      }
      if($this->input->post('iddept'))
      {
        $this->db->where('iddept', $this->input->post('iddept'));
      }
      //if($this->input->post('idsubdept'))
      //{
      //  $this->db->like('LastName', $this->input->post('LastName'));
      //}
      if($this->input->post('kodenik'))
      {
        $this->db->like('kodenik', $this->input->post('kodenik'));
      }
      if($this->input->post('namakry'))
      {
        $this->db->like('namakary', $this->input->post('namakry'));
      }

      $this->db->from($this->kary_table);

      $i = 0;

      foreach ($this->kary_column_search as $item) // loop column 
      {
        if($_POST['search']['value']) // if datatable send POST for search
        {

          if($i===0) // first loop
          {
            $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
            $this->db->where($item, $_POST['search']['value']);
          }
          else 
          {
            if($i===1) // second loop (iddept)
            {
              $this->db->where($item, $_POST['search']['value']);
            }
            else
            {
              $this->db->like($item, $_POST['search']['value']);  
            } 
          }

          if(count($this->kary_column_search) - 1 == $i) //last loop
            $this->db->group_end(); //close bracket
        }
        $i++;
      } 

    }    

  public function count_all()
    {
        $this->_get_listkary_count();
        return $this->db->count_all_results();
    }

  function count_filtered()
    {
        $this->_get_listkary_count();
        $query = $this->db->get();
        return $query->num_rows();
    }
}

/* End of file assetfiltermdl.php */
/* Location: ./application/models/assetfiltermdl.php */
<div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h1> Data Karyawan </h1>
                    <h2> Informasi Data Karyawan </h2>
                    <p>
                        <a href ="<?php echo base_url('asset/karyawantambahform'); ?>" class="btn btn-primary">Tambah Karyawan Baru</a>   
                    </p>
              </div>

            </div>
            <div class="clearfix"></div>

          <div class = "row">

            <div class="col-md-12 col-sm-12 col-xs-12">
              <div class="x_panel">
                <div class="x_title">
                  <h2>Daftar Karyawan</h2>
                  <ul class="nav navbar-right panel_toolbox">
                    <li><a href="#"><i class="fa fa-chevron-up"></i></a>
                    </li>
                    <li class="dropdown">
                      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                    </li>
                    <li><a href="#"><i class="fa fa-close"></i></a>
                    </li>
                  </ul>
                  <div class="clearfix"></div>
                </div>
                <div class="x_content">

                <form id="form-filter" class="form-horizontal">
                    <div class="item form-group">
                        <label for="idper" class="col-sm-2 control-label">Perusahaan</label>
                        <div class="col-sm-4">
                            <select class="select2_single form-control" tabindex="-1" id="idper" name="idper">
                                <option>Pilih Perusahaan</option>
                                <?php foreach ($perushlov as $key => $value) { ?>
                                    <option value="<?php echo $value['idper']?>"><?php echo $value['namaper']?></option>}
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    <div class="item form-group" >
                        <label for="iddept" class="col-sm-2 control-label">Departemen :</label> 
                        <div class="col-sm-4">
                            <select class="select2_single form-control" tabindex="-1" id="iddept" name="iddept">
                                    <option >Pilih Departement</option>
                                    <?php foreach ($deptlov as $key => $value) { ?>
                                        <option value="<?php echo $value['iddept']?>"><?php echo $value['kodedept'] . ' - ' . $value['namadept'] . ' - ' . $value['namaper'] ?></option>}
                                    <?php } ?>
                            </select>
                        </div>
                    </div>
                    <div class="item form-group">
                        <label for="kodenik" class="col-sm-2 control-label">Nama Karyawan</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="namakry">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label for="kodenik" class="col-sm-2 control-label">Kode NIK</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="kodenik">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label for="LastName" class="col-sm-2 control-label"></label>
                        <div class="col-sm-4">
                            <button type="button" id="btn-filter" class="btn btn-primary">Filter</button>
                            <button type="button" id="btn-reset" class="btn btn-default">Reset</button>
                        </div>
                    </div>
                 </form>
                 <!-- <table id="datatable-buttons" class="table table-striped table-bordered"> -->
                <table id="master_karyawan" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                 <thead>
                    <tr>
                        <th>Id</th>
                        <th>Kode Nik</th>
                        <th>Nama Karyawan</th>
                        <th>Perusahaan</th>
                        <th>Departemen</th>
                        <th>Jabatan</th>
                        <th>Aktif</th>
                        <th>Administrasi</th>
                    </tr>           
                </thead>
                <tbody> 
                </tbody>
                </table>
                </div>
              </div>
            </div>
          </div>
        </div>

<script type="text/javascript">

var table;

$(document).ready(function() {

    //datatables
    table = $('#master_karyawan').DataTable({ 

        "processing": true, //Feature control the processing indicator.
        "serverSide": true, //Feature control DataTables' server-side processing mode.       
        "order": [], //Initial no order.

        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "<?php echo base_url('index.php/Assetfilter/kary_reload')?>",
            "type": "POST",
            "data": function ( data ) {
                data.perush = $('#idper').val();
                data.depart = $('#iddept').val();
                data.namakry = $('#namakry').val();
                data.kodenik = $('#kodenik').val();
            }
        },

        //Set column definition initialisation properties.
        "columnDefs": [
        { 
            "targets": [ 0 ], //first column / numbering column
            "orderable": false, //set not orderable
        },
        ],

        //$.fn.dataTable.ext.errMode = 'throw';

    });

    $('#btn-filter').click(function(){ //button filter event click
        table.ajax.reload(null,false);  //just reload table
    });
    $('#btn-reset').click(function(){ //button reset event click
        $('#form-filter')[0].reset();
        table.ajax.reload(null,false);  //just reload table
    });

});

</script>
public function index()
    {
        $this->load->helper('url');
        $this->load->helper('form');

        $list = $this->assetfiltermdl->get_listkary();

        $opt = array('' => 'All List Karyawan');
        foreach ($karyawans as $karyawan) {
            $opt[$karyawan] = $karyawan;
        }

        $data['form_karyawan'] = form_dropdown('',$opt,'','id="karyawan" class="form-control"');
        $this->load->view('karyawan_view', $data);
    }