codeigniter 数据表下一个和上一个按钮在第 2 页之后不起作用

问题描述 投票:0回答:1

codeigniter 数据表下一个和上一个按钮在第 2 页后不起作用 下一个按钮单击没有任何 ajax 调用,如果我单击任何页面(如第 4 页,从 1,2,3,4,5 按钮,它会工作

请提供此错误解决方案

$(document).ready(function() {

// setTimeout(function(){  $("#search-filter").click(); $('#filter_btn').click(); }, 10);
    Array.from(document.getElementsByClassName("flatpickr-months"))
    .forEach(function(element){
        element.addEventListener("click", function(event){ event.preventDefault(); event.stopPropagation(); });
    });

    table = $('#dynamic_datatable').DataTable({
      processing: true,
      serverSide: true,
      stateSave: true,
      ordering: true,
      lengthChange: true,
      pageLength: 10, // Set the number of records per page to 10
      paging: true, // Enable pagination
      /*
      fixedColumns: {
        start: 1,
        end: 1
    },
    */
    pageLength: '<?= getPagePerData() ?>',
      language: {
        search: "_INPUT_",
        searchPlaceholder: "<?=lang('App.Search');?>...",
        info: "<?=lang('App.Showing')?> _START_ <?=lang('App.to')?> _END_ <?=lang('App.of')?> _TOTAL_ <?=lang('App.entries')?>",
        lengthMenu: "<?=lang('App.Show')?> _MENU_ <?=lang('App.entries')?>",
        paginate: {
          "next": "<?=lang('App.Next')?>",
          "previous": "<?=lang('App.Previous')?>"
        },
      },
      stateSaveCallback: function(settings, data) {
        localStorage.removeItem('DataTables_' + settings.sInstance, JSON.stringify(data))
        //localStorage.setItem( 'DataTables_' + settings.sInstance, JSON.stringify(data) )
      },
      stateLoadCallback: function(settings) {
        return JSON.parse(localStorage.getItem('DataTables_' + settings.sInstance))
      },
      ajax: '<?=base_url('get-contact-list')?>',
      order: [
        [0, 'desc']
      ],
      columns: [{
          targets: 0,
          data: 'id',
          name: 'id',
          visible: false,
          searchable: false
        },
        {
          data: 'name',
          name: 'name',
          class: "editableField opencls name"
        },
        {
          data: 'notes',
          name: 'notes',
          orderable: false,
          searchable: false
        },  
        {
          data: 'status',
          name: 'status',
          className: 'editableField status',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('status', $customization->contact) ? 'true' : 'false');?>,
        },        
        {
          data: 'job_title',
          name: 'job_title',
          className: 'editableField job_title',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('job_title', $customization->contact) ? 'true' : 'false');?>,
        },     
        {
          data: 'account_id',
          name: 'account_id',
          className: 'editable editableField opencls account_id',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('account_id', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'deal_id',
          name: 'deal_id',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('deal_id', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'property_id',
          name: 'property_id',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('property_id', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'contact_type_id',
          name: 'contact_type_id',
          className: 'editableField contact_type_id',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('contact_type_id', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'mobile_number',
          name: 'mobile_number',
          class: "editableField mobile_number",
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('mobile_number', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'email',
          name: 'email',
          class: "editableField email",
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('email', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'national_id',
          name: 'national_id',
          class: "editableField national_id",
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('national_id', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'comment',
          name: 'comment',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('comment', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'updated_at',
          name: 'updated_at',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('updated_at', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'created_by',
          name: 'created_by',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('created_by', $customization->contact) ? 'true' : 'false');?>,
        },
        {
          data: 'created_at',
          name: 'created_at',
          visible: <?=(empty($customization->contact)) ? 'false' : (in_array('created_at', $customization->contact) ? 'true' : 'false');?>,
        },
      ],

      colReorder: true,
      scrollX: true,
    });

下一个按钮在第 2 页上不起作用,如果我在第 1 页上单击 1,则下一个按钮可以工作

php codeigniter datatable datatables
1个回答
0
投票

您可以尝试使用下面的代码吗?

var handleCountryList = function () {

        var recordPerPage = 10;
        var dataTable = $("#countryList1").DataTable({
            "dom":"<'row'<'col-sm-12'lip>>"+ "<'row'<'col-sm-12'tr>>" +"<'row'<'col-sm-12'lip>>",
            "iDisplayLength": recordPerPage,
            "serverSide": true,
            "responsive": true,
            "bRetrieve": true,
            "processing": true,
            "paging": true,
            "searching": true,
            "info": true,
            "ordering": true,
            "bSort": true,
            "oLanguage": {"sEmptyTable": 'No Records Found', "sZeroRecords": 'No records Found',
                "oPaginate": {
                    "sNext": "<i class='fa fa-caret-right'></i>",
                    "sPrevious": "<i class='fa fa-caret-left'></i>"
                }
            },
            "ajax": {
                url: baseURL + "country/countryList/",
                type: "POST"
            },
            "aoColumnDefs": [
                {
                    'bSortable': false,
                    'aTargets': [3,4]
                }],
            "columns": [
                {
                    "targets": [0],
                    "render": function (data, type, row) {
                        return row.Name;
                    }
                },
                {
                    "targets": [1],
                    "render": function (data, type, row) {
                        return row.Code;
                    }
                },
                {
                    "targets": [2],
                    "render": function (data, type, row) {
                        return row.ISO3;
                    }
                },
                {
                    "targets": [3],
                    "render": function (data, type, row) {
                        return row.StatusData;
                    }
                },
                {
                    "targets": [4],
                    "render": function (data, type, row) {
                        return row.ActionData;
                    }
                }
            ],
        });
}

我的模型代码将是这样的

public function getCountryList() {
        $data = array();
        $recordsTotal = array();
        $responseData = array();
        $search = $_POST['search']['value'];
        $start = $_POST['start'];
        $length = $_POST['length'];

        if (isset($_POST['order'][0]['column'])) {
            $colOrder = $_POST['order'][0]['column'];
        }
        if (isset($_POST['order'][0]['dir'])) {
            $coldir = $_POST['order'][0]['dir'];
        }

        if ($colOrder == 0) {
            $col = TBLCOUNTRY . ".CountryName";
        }
        else if ($colOrder == 1) {
            $col = TBLCOUNTRY . ".CountryCode";
        }
        else if ($colOrder == 2) {
            $col = TBLCOUNTRY . ".CountryISO3";
        }
        else {
            $col = TBLCOUNTRY . ".CountryID";
        }

        $this->db->start_cache();
        $this->db->select(array(TBLCOUNTRY . ".CountryID", TBLCOUNTRY . ".CountryName", TBLCOUNTRY . ".CountryCode", TBLCOUNTRY . ".CountryISO3", TBLCOUNTRY . ".ActiveYN"));
        $this->db->from(TBLCOUNTRY);
        $this->db->where('IsDeleted =', 0);
        
        if( !empty($_POST['columns'][0]['search']['value'])){   //CountryName
            $this->db->where(TBLCOUNTRY . '.CountryName like "%' . $this->db->escape_like_str($_POST['columns'][0]['search']['value']) . '%"');
        }
        if( !empty($_POST['columns'][1]['search']['value'])){   //StateName
            $this->db->where(TBLCOUNTRY . '.CountryCode like "%' . $this->db->escape_like_str($_POST['columns'][1]['search']['value']) . '%"');
        }
        if( !empty($_POST['columns'][2]['search']['value'])){   //StateCode
            $this->db->where(TBLCOUNTRY . '.CountryISO3 like "%' . $this->db->escape_like_str($_POST['columns'][2]['search']['value']) . '%"');
        }
        if( !empty($_POST['columns'][3]['search']['value'])){   //Enable & Disable
            if($_POST['columns'][3]['search']['value'] == 2)
                    $_POST['columns'][3]['search']['value'] = 0; 
            $this->db->where(TBLCOUNTRY . ".ActiveYN = '" . $_POST['columns'][3]['search']['value'] . "'");
        }
        $this->db->stop_cache();
        $recordsTotal = $this->db->count_all_results();
        $this->db->limit($length, $start);
        $this->db->order_by($col, $coldir);
        $countryList = $this->db->get();
        if ($countryList->num_rows() > 0) {
            foreach ($countryList->result() as $countryKey => $countryVal) {

                $data[$countryKey] = array(
                    'Name' => $countryVal->CountryName,
                    'Code' => $countryVal->CountryCode,
                    'ISO3' => $countryVal->CountryISO3
                );
                $this->db->flush_cache();

                $data["$countryKey"]["StatusData"] = '<div class="btn-group" id="toggle_event_editing">
                    <button onclick="Country.changeStatus(' . $countryVal->CountryID . ',1)" type="button" class="btn locked_active">Enable</button>
                    <button onclick="Country.changeStatus(' . $countryVal->CountryID . ',0)"  type="button" class="btn unlocked_inactive">Disable</button>
                    </div>';
                $data[$countryKey]["ActionData"] = "<a class='fa fa-pencil edit-action' onclick='Country.editData(" . $countryVal->CountryID . ")'></a>"
                        . "<a class='fa fa-trash del-action' onclick='Country.deleteData(" . $countryVal->CountryID . ")'></a>";
            }
        }
        $responseData["recordsTotal"] = $recordsTotal;
        $responseData["recordsFiltered"] = $recordsTotal;
        $responseData["data"] = $data;
        return $responseData;
}
© www.soinside.com 2019 - 2024. All rights reserved.