服务器端处理数据表SSP库

时间:2015-10-21 10:44:57

标签: sql-server datatables sql-order-by ssp

我需要在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 )
    );
}

1 个答案:

答案 0 :(得分:0)

在客户端使用order选项,而不是指定表的初始顺序。

例如:

$('#example').DataTable({
    "order": [[ 1, 'asc' ]]
});