zoukankan      html  css  js  c++  java
  • easy ui datagrid 数据分页

    参照easyui官方网站提供的demo写了个datagrid数据分页的demo,

    具体参数我就不一一罗列了,详细见官方网站,

    这里只介绍一下具体的注意事项和常乃用到的几项,

     1  $('#test').datagrid({
     2                 iconCls: 'icon-save',
     3                 nowrap: false,
     4                 striped: true,
     5                 url: 'UserHandler.ashx?action=List',
     6                 title: 'DataGird',
     7                 loadMsg: "正在加载,请稍等...",
     8                  350,
     9                 height: 300,
    10                 singleSelect: true,
    11                 columns: [[
    12                     { field: 'UserName', title: '编号',  80 },
    13                     { field: 'Password', title: '姓名',  100 },
    14                 ]],
    15                
    16                 pagination: true,
    17                 rownumbers: true
    18             });

    具体的列,在代码中11到14行,其中UserName和Password对应json字符串中的键,
    注意:这里“pagination:true”必须显式加上,默认为false,

    再来看服务器端:

     1  int pageSize = 10;//通过这个获取得到pageSize
     2             int pageNum = 0;//通过这个获取得到pageNum
     3 
     4             if (Request["page"] != null)
     5             {
     6                 int.TryParse(Request["page"], out pageNum);
     7             }
     8 
     9             if (Request["rows"] != null)
    10             {
    11                 int.TryParse(Request["rows"], out pageSize);
    12             }
    13 
    14             string resultStr = "";
    15            
    16             resultStr += "{"total":" + lsFileType.Count + ","rows":[";
    17             for (int i = (pageNum - 1) * pageSize; i < pageSize; i++)
    18             {
    19                 resultStr += "{";
    20                 resultStr += string.Format(""UserName": "{0}", "Password": "{1}"", lsFileType[i].UserName, lsFileType[i].Password);
    21                 resultStr += "},";
    22             }
    23             resultStr = resultStr.Substring(0, resultStr.Length - 1);
    24             resultStr += "]}";

    需要注意的是:total和rows需要加上引号,开始我写成这样,
    resultStr += "{total:" + lsFileType.Count + ",rows:[";

    一直不显示数据。

    demo下载

  • 相关阅读:
    Animate.css 一款强大的预设css3动画库
    关于js返回上一页的实现方法
    jquery判断字符串中是否包含特定字符的方法总结
    去掉select在苹果手机上的原生样式
    html5中如何去掉input type date默认样式
    JS和jQuery中ul li遍历获取对应的下角标
    滚动一定的高度底色递增
    喵哈哈村的狼人杀大战(5)
    喵哈哈村的狼人杀大战(2)
    One Card Poker
  • 原文地址:https://www.cnblogs.com/langhua/p/3140179.html
Copyright © 2011-2022 走看看