javascript - 数据表。服务器端处理。如何获取表的信息?

标签 javascript c# jquery asp.net datatables

我正在尝试遵循以下示例:https://www.datatables.net/manual/server-side

示例中的 JavaScript 代码:

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "scripts/server_processing.php"
    } );
} );

HTML 代码:

<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>First name</th>
                <th>Last name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th>First name</th>
                <th>Last name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>

这是服务器端脚本:

<?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 = 'datatables_demo';

// 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' => 'first_name', 'dt' => 0 ),
    array( 'db' => 'last_name',  'dt' => 1 ),
    array( 'db' => 'position',   'dt' => 2 ),
    array( 'db' => 'office',     'dt' => 3 ),
    array(
        'db'        => 'start_date',
        'dt'        => 4,
        'formatter' => function( $d, $row ) {
            return date( 'jS M y', strtotime($d));
        }
    ),
    array(
        'db'        => 'salary',
        'dt'        => 5,
        'formatter' => function( $d, $row ) {
            return '$'.number_format($d);
        }
    )
);

// 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 )
);

服务器如何接收表的信息?当前页码、显示的记录数等? 我如何将此信息传递给 ASP.NET MVC Controller ?

最佳答案

我在there找到

使用 jQuery DataTables 和 ASP.NET Mvc 进行服务器端过滤、排序和分页

关于javascript - 数据表。服务器端处理。如何获取表的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181463/

相关文章:

C# 在客户端和服务器上使用 TcpListener

javascript - 使用 URL 参数触发 Javascript

jquery - Mobile Jquery - 翻转效果

javascript - 刷新 Div 内容不起作用?

javascript - 获取 ID 并将其传递给 jQuery 脚本

javascript - 返回之前设置状态总是失败,因为它尚未完成 react

javascript - VueJS 将 v-model 属性从子级发送到父级

c# - 在 unity3d 中通过标签查找不活动的游戏对象

c# - Qyoto 是一个可行的平台吗?

javascript - Uncaught ReferenceError : $ is not defined at http://localhost/project/public/user/1/edit:308:9 in Laravel