datatable使用笔记
2014-04-03 17:29
113 查看
页面向后台传数据:
后台解数据:
var oTable = $('#sample_2').dataTable( { "aoColumnDefs": [ { "aTargets": [ 0 ] } ], "aaSorting": [[1, 'asc']], "aLengthMenu": [ [5, 15, 20, -1], [5, 15, 20, "全部"] // change per page values here ], // set the initial value bPaginate : true, // 是否分页,默认为 true,分页 bLengthChange : true, // 是否允许用户通过一个下拉列表来选择分页后每页的行数。行数为 10,25,50,100。这个设置需要 bPaginate 支持。默认为 true。 "iDisplayLength": 10, "bProcessing": true, "sAjaxSource" : "../../appcontroller/applist.json?currpage=1&pagesize=10", "sAjaxDataProp" : "list", "bServerSide" : true, // 异步请求必须设置 // "sPaginationType": "full_numbers", "aoColumns": [ {"mDataProp":"id"}, {"mDataProp":"icon", "mRender": function(data, type, full) { return '<img style="max-width: 57px;max-height: 57px;" src=' + data + ' />'; } }, {"mDataProp":"title"}, {"mDataProp":"price"}, {"mDataProp":"createtime"}, {"mDataProp":"updatetime"}, {"mDataProp":"state", "mRender": function(data, type, full) { var value = "已发布" if ("0" == data){ value = "草稿" } else if("-1" == data){ value = "已删除" } return value } } ], "fnServerData" : function(sSource, aoData, fnCallback){ $.ajax({ "type" : "get", "contentType" : "application/json", "url" : sSource, "dataType" : "json", "data" : { aoData :JSON.stringify(aoData) }, // 以json格式传递 "success" : function(resp) { if(resp){ fnCallback(resp); } else { fnCallback({"list":[]}); } } }) }, "oLanguage": { "sProcessing": "正在加载中......", "sLengthMenu": "每页显示 _MENU_ 条记录", "sZeroRecords": "对不起,查询不到相关数据!", "sEmptyTable": "表中无数据存在!", "sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", "sInfoFiltered": "数据表中共为 _MAX_ 条记录", "sSearch": "搜索", "oPaginate": { "sFirst": "首页", "sPrevious": "上一页", "sNext": "下一页", "sLast": "末页" } } //多语言配置 });
后台解数据:
$aoData = $_GET['aoData']; $sEcho = 1; $iDisplayStart = 0; // 开始下标 $iDisplayLength = 10; // 每页记录数(这两个参数是从前台传过来的,用作分页查询) if($aoData) { $aoDataJson = json_decode($aoData); foreach($aoDataJson as $value) { $nameKey = $value->name; $valueKey = $value->value; if($nameKey == "sEcho") { $sEcho = $valueKey; } elseif($nameKey == "iDisplayStart") { $iDisplayStart = $valueKey; } elseif($nameKey == "iDisplayLength") { $iDisplayLength = $valueKey; } } } $title = $_GET['title']; $is_offline = $_GET['is_offline']; $state = $_GET['state']; $pagesize = $iDisplayLength and $iDisplayLength or $_GET['pagesize']; $currpage =$sEcho and $sEcho or $_GET['currpage']; ! $pagesize && $pagesize = 12; ! $currpage && $currpage = 1; $condition = array(); $title && $condition['title'] = $title; $is_offline && $condition['is_offline'] = $is_offline; $state && $condition['state'] = $state; $pagesize && $condition['pagesize'] = $pagesize; $currpage && $condition['currpage'] = $currpage; $service = $this->App_model->findListApp($condition); $service['returncode'] = '000000'; $service['iTotalRecords'] = 3; // 总记录数 $service['iTotalDisplayRecords'] = 30; // 当前页包含的记录数(这两个是必须返回的) return $service;
相关文章推荐
- 转载:QTP笔记(关于datatable及语句使用)
- datatable使用笔记
- 关于JQUERY的DataTable插件的使用过程笔记【持续更新中……】
- DataTable初次使用笔记
- php学习笔记(二十五)php中cookie的使用和控制
- java学习笔记---Java中批处理SQL的使用方法(JDBC)
- Apache服务器运维笔记(2)----使用apxs来进行编译安装 mod_txt 模块
- AngularJS1.0的使用总结笔记------005
- PHP学习笔记(8)验证码使用session对比
- 学习笔记(二)ubuntu16.04下Qt+opencv的安装配置及使用
- ireport学习笔记---java应用程序中使用报表篇
- tinyxml使用笔记与总结
- OpenJDK源码研究笔记(十六):在Java中使用JavaScript脚本语言
- iOS开发笔记--使用blend改变图片颜色
- Rhino 使用笔记
- STRUTS2 验证框架--WebWork Validation使用笔记
- 对之前.net项目datatable方面的使用总结
- DataTable学习笔记---排序细则、列隐藏
- [Slackware13.0学习笔记]近来使用的感想
- mxGraph使用笔记