程序从后台读取数据后分页、查找等功能都不能用了
代码如下 
html
 <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
  <colgroup>
                        <col class="con0" style="width: 4%" />
                        <col class="con1" />
                        <col class="con0" />
                        <col class="con1" />
                        <col class="con0" />
                        </colgroup>
                    <thead>
                        <tr>    
                            <th class="head0">编号</th>
                            <th class="head1">用户名</th>
                            <th class="head0">性别</th>
                            <th class="head1">备注</th>
                            <th class="head0">分组</th>
                            <th class="head1">关注时间</th>
                            <th class="head0">最近访问</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th class="head0">编号</th>
                            <th class="head1">用户名</th>
                            <th class="head0">性别</th>
                            <th class="head1">备注</th>
                            <th class="head0">分组</th>
                            <th class="head1">关注时间</th>
                            <th class="head0">最近访问</th>
                        </tr>
                    </tfoot>
      <tbody>
      </tbody>
</table>js===============================================================
 jQuery(document).ready(function() {
   jQuery('#dyntable').dataTable({
     "processing": true,
         "serverSide": true,
            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "所有"]],
        "bLengthChange": true, 
     "ajax": "../../../data.php",
            "bStateSave" :false,
       "iDisplayLength" : 10,// 每页显示行数
             "sPaginationType" : "full_numbers",
                "oLanguage": {
      "sUrl": "cn.txt"
     },
     "aoColumns": [
      { "data": "index" },

                         { "data": "nickname" },

                         { "data": "sex" },                         { "data": "re" },                         { "data": "groupid" },                         { "data": "subscribe_time" },                         { "data": "recent" }
     ]
           
});
    });
后台===============================================================
include("includes/json_encode_ex.php");
include("includes/database.php");
$db = new database();
$db->database_connection();
$sql  = "SELECT * FROM T_WechatUserInfo";
$dd = $db->database_operation($sql);
$db->database_close();
$sum =count($dd);
$data=array(          "draw"=>2,       "iTotalRecords"=>$sum,          "iTotalDisplayRecords"=> 10,          "data"=>$dd,      );$temp = new json_encode_ex();
echo $temp->JSON($data);
现在能把服务器端的数据全部显示到浏览器上,但是无法分页,我指定一页只能显示10条数据但还是会把所有数据全部显示出来

解决方案 »

  1.   

    分页的处理是通过SQL语句实现的,你后台代码没有分页的功能。分页方法网上很多,比如
    http://tech.163.com/05/1226/08/25SSNRL20009159K.html
    http://blog.sina.com.cn/s/blog_8231283801018h8n.html
      

  2.   

    把bServerSide配置去掉,否则你需要在服务器端分页返回指定页数的数据,datatable不会使用客户端分页
      

  3.   

    举个栗子
    function initList() {
        $("#datatable").dataTable({
            "pagingType": "simple_numbers",//设置分页控件的模式  
            "searching": false,//屏蔽datatales的查询框  
            "aLengthMenu":[10],//设置一页展示10条记录  
            "bLengthChange": true,//屏蔽tables的一页展示多少条记录的下拉列表  
            "sAjaxSource": "project_projectManage", // post请求方法
            "sServerMethod": "POST",             
            "destroy":true,
            "ordering" :false, //禁用排序
            "serverSide": true,//打开后台分页  
            "fnServerParams": function (aoData) {
                aoData.push(
                { "name": "scode_pro", "value": $('#scode_pro').val() },
                { "name": "sname_pro", "value": $('#sname_pro').val() },
                { "name": "sname_usr", "value": $('#sadviser_pro').val()},
                   { "name": "nstatus_pro", "value": $('#nstatus_pro option:selected').val() });
            },
            "aLengthMenu": [[20,50, 100], [20,50,100]],
            "aoColumns": [
                          {"data": "scode_pro","sClass":"table_left"},
                          {"data": "sname_pro","sClass":"table_left"},
                          {"data": "sname_usr","sClass":"table_left"},
                          {"data": "proState"}
                          
                          ],
                          
            "columnDefs": [        
                          {"targets": [4],
                           "data": "sname_pro",
                           "render": function(data, type, full) {
                         if(full.proState == '进行中'){
                         return "<td class='content-line-td' width='15%'><a href=\"#\"  style='width: 50px;' onclick=\"modify('"+full.nid_pro+"');\">修改</a>&nbsp;"+
                                "<a href=\"#\"  style='height: 16px; line-height: initial;'  onclick=\"del('"+full.nid_pro+"','"+full.sname_pro+"');\">  删除</a>&nbsp;"+    
                                "<a href=\"#\"  style='height: 16px; line-height: initial;'  onclick=\"endProject('"+full.nid_pro+"','"+full.sname_pro+"');\">  结束</a>&nbsp;"+
                                 "</td>";
                         }else{
                         return "<td class='content-line-td' width='15%'><a href=\"#\"  style='width: 50px;' onclick=\"startProject('"+full.nid_pro+"','"+full.sname_pro+"');\">再开始</a>&nbsp;"+                        
                                 "</td>";
                         }
                               },"sClass":"table_left"
                           },
                     ],  
               "oLanguage":{  
                    "sLengthMenu": "每页显示 _MENU_ 条记录",     
                               "sZeroRecords": "没有检索到数据",     
                               "sInfo": "显示 _START_-_END_ 条数据,共有 _TOTAL_ 条记录。",     
                               "sInfoEmtpy": "没有数据",     
                               "sProcessing": "正在加载数据...",     
                               "oPaginate":   
                               {     
                                   "sFirst": "首页",     
                                   "sPrevious": "上一页",     
                                   "sNext": "下一页",     
                                   "sLast": "尾页"    
                               }     
               },  
            "fnServerData": function (sUrl, aoData, fnCallback) {
                $.ajax({
                    "url": sUrl,
                    "data" :aoData,
                    "success": fnCallback,
                    "dataType": "json",
                    "cache": false,
                    "success" : function(resp) {  
                        fnCallback(resp);  
                        $("#datatable td").each(function(i){
                          //给td设置title属性,并且设置td的完整值.给title属性.
                          $(this).attr("title",$(this).text());
                 });
                    }  
                });
            }
        });
    };
    -------------------------------------------
      aoData.push 里面是检索的参数
    aoColumns页面显示的数据
    后台接收的分页参数如下
      

  4.   

    sEcho = Integer.valueOf(request.getParameter("sEcho"));
    iDisplayLength = Integer.valueOf(request.getParameter("iDisplayLength"));
    iDisplayStart = Integer.valueOf(request.getParameter("iDisplayStart"));
    sql += " ORDER BY `nid_sup`  limit "+iDisplayStart+","+iDisplayLength+"  "; 翻页
    ------------------------------------------------
    返回的json格式如下
    arraySize -->检索出来的数据。arraySize   数据大小
    public static StringBuffer JsonUtils(List<?> objcet, int arraySize,String jsonArray,int sEcho){
    StringBuffer json = new StringBuffer();
    json.append("{");
    json.append("\"sEcho\"" + ":" + sEcho + "");
    json.append(",");
    json.append("\"iTotalRecords\"" + ":" + arraySize + "");
    json.append(",");
    json.append("\"iTotalDisplayRecords\"" + ":" + arraySize + "");
    json.append(",");
    json.append("\"aaData\":");
    json.append("[");
    if (objcet != null && objcet.size() > 0) {
    for (Object obj : objcet) {
    JSONArray object = JSONArray.fromObject(obj);
    String replactobj = object.toString().replaceAll("^.*\\[", "")
    .replaceAll("].*", "");
    json.append(replactobj);
    json.append(",");
    }
    } else {
    json.append("}");
    }
    json.setCharAt(json.length() - 1, ']');
    json.append("}");
    return json;

    }
    ----------------------
    觉得有用给分哦