我正在尝试遵循以下规则: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控制器?
参考方案
我在there找到了
结合使用jQuery DataTables和ASP.NET Mvc进行服务器端过滤,排序和分页
当<form>'.submit'函数被覆盖时(使用Ajax)将数据获取到php吗? - javascript我已覆盖此网页上表单的.submit函数,因为该网页已加载在“ index.php”中的#mainContent内,并且我希望“提交”按钮仅替换此#mainContent。我正在尝试将数据从此表单获取到.php文件,以便对数据库进行查询(或简单地回显已填充的变量,以指示已传递数据)。我是AJAX的新手。有人可以向我解释如何将数据传递到.php文件,或者指向要…
如何在HTML选项中添加onClick? - javascript我要尝试的是单击<option>时,该值将显示在<input type='text'>中现在是我的代码:<select id='months'> <option value='9' id='months9'>9 Months<…
在AJAX中向表添加JSON数据 - javascript好的,我从输入框中有一些搜索结果。我使用keyup获得结果。然后此结果发送到AJAX,我想将其附加到表中。我的问题是因为如果我有更多结果,我将使用append来获取多个表头,另一方面,由于脚本使用for循环,因此我将无法使用html(),因此我只会得到一个结果。有人可以帮我解决这个问题。我尝试这样的事情...$("#search").ke…
混合码错误 - javascript好的,我在网站上为用户个人资料提供了一个基本的多合一页面,如下所示:<?php if($_GET['p']=='pb'){ echo '<p>pb</p>'; }elseif($_GET['p']=='example2'){ ec…
在删除前不提示使用JavaScript提示 - javascript我有一个页面,其中列出了数据库中表的内容,并且试图添加一个按钮以删除行。我查了一下,然后用JavaScript做到了,但是没有用。//Deletion if (isset($_GET['sup'])) { $sup = $_GET['sup']; $sql=mysql_query("delete from U…