0

我需要在 SSP 库中使用 order 函数,该函数用作数据表中的服务器端处理。我不知道如何传递我需要对结果进行排序的列。

// DB table to use
    $table = 'crowd_sourcing_products';

// Table's primary key
    $primaryKey = 'id';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
    $columns = array(

        array('db' => `p` . 'id', 'field' => 'id', 'dt' => 'DT_RowId', 'formatter' => function( $d, $row ) {
                // Technically a DOM id cannot start with an integer, so we prefix
                // a string. This can also be useful if you have multiple tables
                // to ensure that the id is unique with a different prefix
                return 'row_' . $d;
            }),
        array('db' => `c` . 'barcode', 'dt' => 0, 'field' => 'barcode'),
        array('db' => `c` . 'package_front_image', 'dt' => 1, 'field' => 'package_front_image', 'formatter' => function( $d, $row ) {
                return '<img src ="'.base_url().'mobilesup/images/' . str_replace('"', '', $d) . '">';
            }),
        array('db' => `c` . 'label1', 'dt' => 2, 'field' => 'label1', 'formatter' => function( $d, $row ) {
                return '<img src ="'.base_url().'mobilesup/images/' . str_replace('"', '', $d) . '">';
            }),
        array('db' => `c` . 'label2', 'dt' => 3, 'field' => 'label2', 'formatter' => function( $d, $row ) {
                return '<img src ="'.base_url().'mobilesup/images/' . str_replace('"', '', $d) . '">';
            }),
        array('db' => `c` . 'net_weight', 'field' => 'net_weight', 'dt' => 4),
        array('db' => `nu` . 'unit_e_value', 'field' => 'unit_e_value', 'dt' => 5)
            // array( 'db' => 'net_weight',     'dt' => 3 )
    );

$joinQuery = "FROM `crowd_sourcing_products` AS `c` left JOIN `nutrition_facts_unit` AS `nu` ON (`c`.`unit_id` = `nu`.`unit_id`)";
    $extraWhere = "`c`.is_deleted <> '1's";    
    $this->load->library('Ssp');

    SSP::order($_GET, $columns);  ////// how to use it??????????
    echo json_encode(
            SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery ,$extraWhere )
    );
}
4

1 回答 1

0

在客户端使用order选项来指定表的初始顺序。

例如:

$('#example').DataTable({
    "order": [[ 1, 'asc' ]]
});
于 2015-10-21T11:44:31.827 回答