首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >服务器端处理datatable SSP库

服务器端处理datatable SSP库
EN

Stack Overflow用户
提问于 2015-10-21 18:44:57
回答 1查看 586关注 0票数 0

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

代码语言:javascript
复制
// 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 )
    );
}
EN

回答 1

Stack Overflow用户

发布于 2015-10-21 19:44:32

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

例如:

代码语言:javascript
复制
$('#example').DataTable({
    "order": [[ 1, 'asc' ]]
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33257237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档