duan0821 2017-07-08 18:32
浏览 41

数据分页不适用于服务器端

I want to show data from database using datatable plugin, but the problem is, it shows all the data in one page and still says showing 1 of 10 and the pagination button appears but won't work.

enter image description here

enter image description here

jquery:

<script>
    $(document).ready(function() {
    $('#leads').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax":{
            url :"includes/get_data_script_test.php", // json datasource
            type: "post",  // type of method  , by default would be get
          }
    } );
} );
</script>

get_data_script_test.php:

<?php

/*
 * DataTables example server-side processing script.
 *
 * Please note that this script is intentionally extremely simply to show how
 * server-side processing can be implemented, and probably shouldn't be used as
 * the basis for a large complex system. It is suitable for simple use cases as
 * for learning.
 *
 * See http://datatables.net/usage/server-side for full details on the server-
 * side processing requirements of DataTables.
 *
 * @license MIT - http://datatables.net/license_mit
 */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Easy set variables
 */

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

// 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' => 'name', 'dt' => 0 ),  
);

// SQL server connection information
$sql_details = array(
    'user' => '**********',
    'pass' => '***********',
    'db'   => '**********',
    'host' => '**********'
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP
 * server-side, there is no need to edit below this line.
 */

require( 'ssp_class.php' );

echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
?>
</div>
  • 写回答

1条回答 默认 最新

  • douyi8315 2017-08-02 16:58
    关注

    To have the pagination work you need to have it setup in jquery script. You would need something like this:

    <script>
        $(document).ready(function() {
        $('#leads').DataTable( {
            "lengthMenu": [[10,15,20,25,-1], [10,15,20,25,'All']], //This line needs added so that it knows what to set the page lengths to
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"includes/get_data_script_test.php", // json datasource
                type: "post",  // type of method  , by default would be get
              }
        } );
    } );
    </script>

    Without the lengthMenu DataTables won't know what to set the page lengths to and will only show all data.

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛