【问题标题】:datatables sorting not working when set orderby设置orderby时数据表排序不起作用
【发布时间】:2016-08-15 14:07:47
【问题描述】:

我有这个数据表。

这是模型,

var $column2 = array('payroll.PAYROLL_FOR','loan_transactions.DATE','loantypes.LOAN_NAME','employee_loans.LOAN','loan_transactions.CUR_BAL','loan_transactions.AMT_PD','loan_transactions.TRANS_STATUS','loan_transactions.DATE');
var $order2 = array('payroll.PAYROLL_FOR' => 'desc');

private function _get_datatables_query2()
{

    $this->db->select('loan_transactions.DATE,
                        loantypes.LOAN_NAME,
                        employee_loans.LOAN,
                        loan_transactions.CUR_BAL,
                        loan_transactions.AMT_PD,
                        loan_transactions.TRANS_STATUS,
                        payroll.PAYROLL_FOR,
                        loan_transactions.DATE');
    $this->db->from($this->table);
    $this->db->join('payroll','loan_transactions.PAYROLL_TRANS_ID = payroll.TRANS_ID','left');
    $this->db->join('employee_loans','loan_transactions.EMP_LOAN_ID = employee_loans.ID','inner');
    $this->db->join('loantypes','employee_loans.LOAN_ID = loantypes.LOAN_ID','left');

    $i = 0;

    foreach ($this->column2 as $item) 
    {
        $this->db->where('loan_transactions.ID_NUM', $this->uri->segment(3));
        if($_POST['search']['value'])
            ($i===0) ? $this->db->like($item, $_POST['search']['value']) : $this->db->or_like($item, $_POST['search']['value']);
        $column2[$i] = $item;
        $i++;
    }

    if(isset($_POST['order2']))
    {
        $this->db->order_by($column2[$_POST['order2']['0']['column2']], $_POST['order2']['0']['dir']);
    } 
    else if(isset($this->order2))
    {
        $order2 = $this->order2;
        $this->db->order_by(key($order2), $order2[key($order2)]);
    }
}

function get_datatables2()
{
    $this->_get_datatables_query2();
    if($_POST['length'] != -1)
    $this->db->limit($_POST['length'], $_POST['start']);
    $query = $this->db->get();
    return $query->result();
}

然后这里是ajax

$(document).ready(function() {
  table1 = $('#table1').DataTable({ 

    "processing": true, //Feature control the processing indicator.
    "serverSide": true, //Feature control DataTables' server-side processing mode.

    // Load data for the table's content from an Ajax source
    "ajax": {
        "url": "<?php echo site_url('LoanTransactionLogs/ajax_list2')?>/<?php echo $_SESSION['user']->ID_NUM; ?>",
        "type": "POST"
    },

    //Set column definition initialisation properties.
    "columnDefs": [
    { 
      "targets": [ -1 ], //last column
      "orderable": true, //set not orderable
    },
    ],
    "aaSorting": [[0, 'desc']],
    "aoColumnDefs": [
      { "bSortable": true, "aTargets": [0] }
    ]
  });
});

此代码在我的其他模块上运行良好。但在这里,排序选项不起作用。我对问题是什么以及如何解决这个问题一无所知。有人可以告诉我问题吗?谢谢。

【问题讨论】:

    标签: jquery codeigniter datatables


    【解决方案1】:

    您可以发布您的回复数据吗?你看过服务器端处理响应数据吗? https://datatables.net/manual/server-side

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多