DataTables 中有两种不同的方式处理数据(排序、搜索、分页等):
  客户端处理(Client)—— 所有的数据集预先加载(一次获取所有数据),数据处理都是在浏览器中完成的【逻辑分页】。
  服务器端处理(ServerSide)—— 数据处理是在服务器上执行(页面只处理当前页的数据)【物理分页】。

ajax从后台获取数据(两种数组方式):

第一种方式:

前端:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- <link rel="stylesheet" href="http://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"> -->
<link href="./css/dataTables.bootstrap.min.css" rel="stylesheet"> <script src="./js/jquery-3.1.1.min.js"></script>
<script src="./js/jquery.dataTables.min.js"></script>
<script src="./js/dataTables.bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<table id="DataTable" class="display table table-striped table-bordered">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>age</th>
</tr>
</thead>
</table>
</div>
<script>
$(function(){
$('#DataTable').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "./server.php",
"type": "POST",
"data": function ( d ) { //添加额外的参数发送到服务器
d.extra_search = 3;
}
}
} );
})
</script>
</body>
</html>

后端:
<?php
$data = array();
//$data['draw'] = 1;
$data['recordsTotal'] = 5;
$data['recordsFiltered'] = 5;
$data['data'] = array(
array("1","Airi","Satou","Accountant","Tokyo","2008/11/28",162700),
array("2","Angelica","Ramos","Chief Executive Officer (CEO)","London","2009/10/09",1200000),
array("3","Ashton","Cox","Junior Technical Author","San Francisco","2009/01/12",86000),
array("4","Bradley","Greer","Software Engineer","London","2012/10/13",132000),
array("5","Bradley","Greer","Software Engineer","London","2012/10/13",132000)
);
shuffle($data['data']); //模拟数据库获取数据
echo json_encode($data);exit;

第二种方式:

前端:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- <link rel="stylesheet" href="http://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"> -->
<link href="./css/dataTables.bootstrap.min.css" rel="stylesheet"> <script src="./js/jquery-3.1.1.min.js"></script>
<script src="./js/jquery.dataTables.min.js"></script>
<script src="./js/dataTables.bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<table id="DataTable" class="display table table-striped table-bordered">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>age</th>
</tr>
</thead>
</table>
</div> <script>
$(function(){
$('#DataTable').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "./server.php",
"type": "POST",
"data": function ( d ) { //添加额外的参数发送到服务器
d.extra_search = 3;
}
},
"columns":[
{"data":"id"},
{"data":"name"},
{"data":"age"}
]
} );
})
</script>
</body>
</html>

  后端:

<?php
$data = array();
//$data['draw'] = 1;
$data['recordsTotal'] = 5;
$data['recordsFiltered'] = 5;
$data['data'] = array(
array("id"=>"1","name"=>"Airi","age"=>"Satou"),
array("id"=>"2","name"=>"Angelica","age"=>"Ramos"),
array("id"=>"3","name"=>"Ashton","age"=>"Cox"),
array("id"=>"4","name"=>"Bradley","age"=>"Greer"),
array("id"=>"5","name"=>"Bradley","age"=>"Greer")
);
shuffle($data['data']);
echo json_encode($data);exit;
 

基于bootstrap 的datatable插件的使用2(php版)的更多相关文章

  1. 基于bootstrap 的datatable插件的使用(php版)

    Datatables是一款jquery表格插件.它是一个高度灵活的工具,可以将任何HTML表格添加高级的交互功能.详细学习请参考其官网:http://datatables.net/中文网:http:/ ...

  2. bootstrap-paginator基于bootstrap的分页插件

    bootstrap-paginator基于bootstrap的分页插件 GitHub 官网地址:https://github.com/lyonlai/bootstrap-paginator 步骤 引包 ...

  3. 基于Bootstrap的对话框插件bootstrap-dialog

    写在前面: bootstrap本身提供了它自己的模态框,但是感觉并不太友好,当需要在页面点击一个按钮打开一个窗口页面时,使用原有的bootstrap的模态框,会把所有的代码全部写在一个jsp页面,显得 ...

  4. 基于bootstrap的分页插件

    之前做的分页,是自己后端写一堆代码,返回给前端页面显示,感觉比较繁重.不灵活.今天研究下基于bootstrap的做的插件,整理如下: 在使用bootstrap的插件的时候,需要导入一些css.js. ...

  5. 基于Bootstrap的DropDownList的JQuery组件的完善版

    在前文 创建基于Bootstrap的下拉菜单的DropDownList的JQuery插件 中,实现了DropDownList的JQuery组件,但是留有遗憾.就是当下拉菜单出现滚动条的时候,滚动条会覆 ...

  6. 基于bootstrap的bootstrap-editable插件实现即时编辑功能

    1.引用基本css和js: <link href="bootstrap3/css/bootstrap.min.css" rel="stylesheet" ...

  7. 基于bootstrap的双日历插件 daterangepicker

    我遇到需求是要求我将daterangepicker的一个双日期选择格式修改成两个单日期格式的日期选择框(方便手机端显示),要求如下: 1.两个单日期格式分别为开始日期和结束日期 2.开始日期可选择范围 ...

  8. 基于Bootstrap的表格插件bootstrap-table

    写在前面: 表格在项目中是使用比较多的,bootstrap-table插件也是非常好用,而且表格页面也比较好看.这里也简单的记录下. 下面直接看demo吧,代码中都注释了,有些用法,这里没有用到,需要 ...

  9. 基于bootstrap的时间选择插件daterangepicker以及汉化方法

    双日历时间段选择插件 — daterangepicker是bootstrap框架后期的一个时间控件: 可以设定多个时间段选项:也可以自定义时间段:由用户自己选择起始时间和终止时间:时间段的最大跨度可以 ...

随机推荐

  1. DS实验题 融合软泥怪-2 Heap实现

    题目和STL实现:DS实验题 融合软泥怪-1 用堆实现优先队列 引言和堆的介绍摘自:Priority Queue(Heaps)--优先队列(堆) 引言: 优先队列是一个至少能够提供插入(Insert) ...

  2. 一个快速double转int的方法(利用magic number)

    代码: int i = *reinterpret_cast<int*>(&(d += 6755399441055744.0)); 知识点: 1.reinterpret_cast&l ...

  3. centos6.7安装Redis

    1.创建安装目录 mkdir /usr/local/redis cd /usr/local/src 2.获取安装包:wget http://download.redis.io/releases/red ...

  4. Java中Map常用方法总结以及遍历方式的汇总

    一.整理: 看到array,就要想到角标. 看到link,就要想到first,last. 看到hash,就要想到hashCode,equals. 看到tree,就要想到两个接口.Comparable, ...

  5. RGB转YCbCr

    从RGB转换成YCbCr //  Purpose:      //          Save RGB->YCC colorspace conversion for reuse, only co ...

  6. Linux TOP命令 按内存占用排序和按CPU占用排序

    P – 以 CPU 占用率大小的顺序排列进程列表M – 以内存占用率大小的顺序排列进程列表 http://blog.csdn.net/xiliuhu/article/details/6449377

  7. WPF 组合快捷键(Ctrl+C)

    页面程序: <Window x:Class="WpfDataGrid.Window1"        xmlns="http://schemas.microsoft ...

  8. Trace-语句启动Profiler中暂停的跟踪会出现什么状况

    2016-09-08 22:09 整理,未发布Profiler创建客户端跟踪.常规页不保存文件.不勾选服务器处理跟踪数据:事件选择RPC:Completed和SQL:BatchCompleted,列筛 ...

  9. onload事件-----addLoadEvent函数

    在给网页加一些特效时经常要在<body>中加入“onload”事件,即在网页加载完后执行某事件,例如:<body onload=”alert(‘欢迎光临!')”,但这样做有个大的缺陷 ...

  10. New line

    The concepts of line feed (LF) and carriage return (CR) are closely associated, and can be either co ...