且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用AJAX进行数据表分页

更新时间:2023-02-11 19:29:59

当然,这对于jquery-dataTables来说很酷.

Of course, this is the cool thing with jquery-dataTables.

看这个例子(针对PHP和MySQL).服务器端数据具有排序和分页

Look at this example (targeted at PHP and MySQL).Server sided Data with sorting and pagination

开箱即用.您要做的是在此PHP行中输入MySQL字段:

This works out of the box. A you have to do is to enter your MySQL fields into this PHP line:

 $aColumns = array( 'engine', 'browser', 'platform', 'version', 'grade' );

如果您正在使用Node/mongoDB或任何其他服务器端脚本,则必须编写自己的代码. 但基本上:

If you are using Node/mongoDB or any other server sided script you will have to write your own code. But basically:

  1. 您在服务器端代码中设置了一个网址
  2. 您可以从请求中由dataTables设置的值(actual_Pagenumber,Items_per_page,按列排序,过滤)限制的任何数据源(db,json文件或其他)中获取数据.只需使用Firebug控制台查看典型请求即可.
  3. 您将json编码的数据返回给客户端(在echo json_encode( $output );中的PHP/MySql中.在node/mongo中,只是查询的结果.
  1. You set an url to your serversided code
  2. You fetch data from any datasource (db, json file or else) clamped by the values dataTables sets in the request(actual_Pagenumber, Items_per_page, sorting for columns, filtering). Just use the firebug console to look at a typical request.
  3. You return json-encoded Data to your client (In PHP/MySql by echo json_encode( $output );. In node/mongo just the result of your query.