EasyUI-DataGrid LoadData加载本地Jsion,并实现分页

不叨叨,先上代码:实际可用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Net_LinerSearch.aspx.cs"
    Inherits="WDWeb.web.Net_LinerSearch" %>


<%@ Import Namespace="Tool" %>
<%@ Register Src="Net_ControlBottom.ascx" TagName="Net_ControlBottom" TagPrefix="uc1" %>
<%@ Register Src="Net_ControlTop.ascx" TagName="Net_ControlTop" TagPrefix="uc2" %>
<%@ Register Src="Net_ControlMenu.ascx" TagName="Net_ControlMenu" TagPrefix="uc3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>网上服务系统</title>
    <link href="css_js/CSS.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="css_js/themes/gray/easyui.css" />
    <link rel="stylesheet" type="text/css" href="css_js/themes/icon.css" />
    <link href="css_js/Pager.css" rel="stylesheet" type="text/css" />
    <script src="../css_js/jQuery.js" type="text/javascript"></script>
    <%--<script src="css_js/jquery-1.7.min.js" type="text/javascript"></script>--%>
    <script type="text/javascript" src="css_js/jquery.easyui.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="css_js/easyloader.js"></script>
    <script src="css_js/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="css_js/jquery.pager.js" type="text/javascript"></script>
    <script type="text/javascript" src="../css_js/layer/layer.min.js"></script>
    <script type="text/javascript">
        $(function () {


            SearchUNameMailInfo();
            SetTable(null);
        });
        //搜索数据信息
        function SearchUNameMailInfo() {
            //btnSerach,txtSerachName,txtSerachMail
            //按条件进行查询信息
            $("#img06").click(function () {
                if ($("#ddlIE").val() == "I") {
                    var queryData = "{ type:'" + $("#ddlIE").val() + "', enname: null, name:'" + $("#ddlStyles").val() + "', mainkey: null }";
                }
                else {
                    var queryData = "{ type:'" + $("#ddlIE").val() + "', enname: null, name:'" + $("#ddlStyles").val() + "', mainkey: null }'";


                }
                // console.log(queryData); //写入控制台查看
                initTable(queryData);
                return false;
            });
        }
        function initTable(querydata) { //***注意querydata参数的写法**:var queryData = "{ AppSetType:'Maerskimportedprecheck',billno:'" + $("#txtNo").val() + "',mainkey:" + null + "}";
            $.ajax({
                type: "POST", //访问WebService使用Post方式请求
                contentType: "application/json;charset=utf-8", //WebService 会返回Json类型
                url: "../GetJsonStr.asmx/GetShipJson", //获取数据的地址
                data: querydata, //参数
                dataType: 'json ',
                beforeSend: function (x) { x.setRequestHeader("Content-Type", "application/json; charset=utf-8"); },
                error: function (x, e) {
                    layer.alert(e.toString(), 0, "友好提醒");
                },
                success: function (data) {
                    var DataObj = $.parseJSON(data.d);
                    var daobj = DataObj.obj;
                    if (daobj != null) {
                        SetTable(daobj);
                    }
                    // $('#dt').datagrid({ loadFilter: SetTable }).datagrid('loadData', daobj);


                }
            });
        };




        //初始化表格
        function SetTable(data) {
            var dg = $("#dt");
            $(dg).datagrid({
                title: '船期信息查询', //标题
                iconCls: 'icon-view',
                border: true, //是否显示边框
                height: function () { return document.div.clientheight * 0.8 }, //面板高度
                //  height: 500,
                width: function () { return document.body.clientwidth * 0.9 }, //面板宽度
                // method: 'POST', //访问远程数据的方法,默认POST
                url: null, //获取数据的地址
                loadMsg: '数据加载中,请稍后……', //数据加载提示,默认"Processing,please wait …"。自定义覆盖。
                // idFiels: 'mainkey', //标识字段Key
                striped: true, //是否显示条纹(即奇偶行使用不同背景色)
                fit: false, //当true时,设置大小以适应它的父容器。默认false。
                fitColumns: true, //True 就会自动扩大或缩小列的尺寸以适应表格的宽度并且防止水平滚动。
                singleSelect: true, //是否只能选中一行数据
                rownumbers: true, //是否显示行号
                pagination: true, //是否显示分页工具栏
                nowrap: false, //是否在同一行显示数据
                pageNumber: 1, //初始化的页码编号,默认1
                pageSize: 10, //每页的数据条数,默认10
                pageList: [10, 20, 50, 100, 150, 200], //页面数据条数选择清单
                //sortName: 'date2', //要排序的列名
                //sortOrder: 'desc', //定义列的排列顺序,只能是'asc'或'desc'。默认asc。
                showFooter: true, //定义是否显示一行页脚
                // queryParams: queryData,  //异步查询的参数  
                data: data == null ? '' : data.slice(0, 10),
                columns: [[
                {
                    field: 'cnname', //关联字段
                    title: '船名', //列名
                    hidden: false,
                    align: 'center',
                    width: 150
                },
                  {
                      field: 'enname', //关联字段
                      title: '英文名', //列名
                      hidden: false,
                      align: 'center',
                      width: 180
                  },
                <span style="white-space:pre">				</span>  {
                <span style="white-space:pre">				</span>      field: 'voyagei', //关联字段
                <span style="white-space:pre">				</span>      title: '船次', //列名
                <span style="white-space:pre">				</span>      sortable: false, //当true时,允许该列进行排序
                <span style="white-space:pre">				</span>      hidden: false,
                <span style="white-space:pre">				</span>      align: 'center',
                <span style="white-space:pre">				</span>      width: 150,
                <span style="white-space:pre">				</span>      formatter: function (value, row, index) {


                <span style="white-space:pre">				</span>          var val = row['voyagei'] + '/' + row['voyagee'];
                <span style="white-space:pre">				</span>          return val;
                <span style="white-space:pre">				</span>      }
                <span style="white-space:pre">				</span>  },
                                  {
                                      field: 'custcname', //关联字段
                                      title: '关区', //列名
                                      sortable: false, //当true时,允许该列进行排序
                                      hidden: false,
                                      align: 'center',
                                      width: 120
                                  },
                                   {
                                       field: 'currberth1', //关联字段
                                       title: '泊位', //列名
                                       sortable: false, //当true时,允许该列进行排序
                                       // hidden: false,
                                       align: 'center',
                                       width: 150,
                                       formatter: function (value, row, index) {
                                           if (row['currberth'] != '预抵' && row['currberth'] != '离港') {


                                               return row['currberth'];


                                           }
                                           else {
                                               return '/';
                                           }
                                       }
                                   },
                <span style="white-space:pre">				</span>  {
                <span style="white-space:pre">				</span>      field: 'currberth', //关联字段
                <span style="white-space:pre">				</span>      title: '船舶状态', //列名
                <span style="white-space:pre">				</span>      sortable: false, //当true时,允许该列进行排序
                <span style="white-space:pre">				</span>      hidden: false,
                <span style="white-space:pre">				</span>      align: 'center',
                <span style="white-space:pre">				</span>      width: 100,
                <span style="white-space:pre">				</span>      formatter: function (value, row, index) {


                <span style="white-space:pre">				</span>          if (row['currberth'] == '预抵') {




                <span style="white-space:pre">				</span>              row['eta11'] = row['eta1'];
                <span style="white-space:pre">				</span>              row['eta12'] = '/';
                <span style="white-space:pre">				</span>              row['eta13'] = '/';
                <span style="white-space:pre">				</span>              return row['currberth'];
                <span style="white-space:pre">				</span>          }
                <span style="white-space:pre">				</span>          else if (row['currberth'] == '离港') {


                <span style="white-space:pre">				</span>              row['eta13'] = row['eta1'];
                <span style="white-space:pre">				</span>              row['eta12'] = '/';
                <span style="white-space:pre">				</span>              row['eta11'] = '/';
                <span style="white-space:pre">				</span>              return row['currberth'];
                <span style="white-space:pre">				</span>          } else {
                <span style="white-space:pre">				</span>              row['eta12'] = row['eta1'];
                <span style="white-space:pre">				</span>              row['eta13'] = '/';
                <span style="white-space:pre">				</span>              row['eta11'] = '/';
                <span style="white-space:pre">				</span>              return '/';
                <span style="white-space:pre">				</span>          }
                <span style="white-space:pre">				</span>      }




                <span style="white-space:pre">				</span>  },


                                   {
                                       field: 'eta11', //关联字段
                                       title: '预抵时间',
                                       sortable: false, //当true时,允许该列进行排序
                                       hidden: false,
                                       align: 'center',
                                       width: 200,
                                       formatter: function (value, row, index) {
                                           if (row['currberth'] == '预抵') {


                                               row['eta12'] = row['eta13'] = '/';


                                               row['eta11'] = row['eta1'];
                                               return row['eta11'];
                                           }
                                           else {
                                               //                                             


                                               return '/';
                                           }
                                       }


                                   },
                <span style="white-space:pre">				</span>  {
                <span style="white-space:pre">				</span>      field: 'eta12', //关联字段
                <span style="white-space:pre">				</span>      title: '靠泊时间',
                <span style="white-space:pre">				</span>      sortable: false, //当true时,允许该列进行排序
                <span style="white-space:pre">				</span>      hidden: false,
                <span style="white-space:pre">				</span>      align: 'center',
                <span style="white-space:pre">				</span>      width: 200,
                <span style="white-space:pre">				</span>      formatter: function (value, row, index) {
                <span style="white-space:pre">				</span>          if (row['currberth'] != '预抵' && row['currberth'] != '离港') {
                <span style="white-space:pre">				</span>               
                <span style="white-space:pre">				</span>              return row['eta1'];


                <span style="white-space:pre">				</span>          }
                <span style="white-space:pre">				</span>          else {
                <span style="white-space:pre">				</span>               
                <span style="white-space:pre">				</span>              return '/';
                <span style="white-space:pre">				</span>          }
                <span style="white-space:pre">				</span>      }
                <span style="white-space:pre">				</span>  },
                                  {
                                      field: 'eta13', //关联字段
                                      title: '离港时间',
                                      sortable: false, //当true时,允许该列进行排序
                                      hidden: false,
                                      align: 'center',
                                      width: 200,
                                      formatter: function (value, row, index) {


                                          if (row['currberth'] == '离港') {
                                              
                                              return row['eta1'];
                                          }
                                          else {
                                               
                                              return '/';
                                          }
                                      }


                                  },
                <span style="white-space:pre">				</span>  {
                <span style="white-space:pre">				</span>      field: 'cname', //关联字段
                <span style="white-space:pre">				</span>      title: '船公司', //列名
                <span style="white-space:pre">				</span>      sortable: false, //当true时,允许该列进行排序
                <span style="white-space:pre">				</span>      hidden: false,
                <span style="white-space:pre">				</span>      align: 'center',
                <span style="white-space:pre">				</span>      width: 360
                <span style="white-space:pre">				</span>  }
                ]]


            });


            if (data != null) {
                var pager = $(dg).datagrid("getPager");
                $(pager).pagination({
                    pageNumber: 1, //初始化的页码编号,默认1
                    pageSize: 10, //每页的数据条数,默认10
                    pageList: [10, 20, 50, 100, 150, 200], //页面数据条数选择清单
                    total: data.length,
                    onSelectPage: function (pageNo, pageSize) {
                        var start = (pageNo - 1) * pageSize;
                        var end = start + pageSize;
                        $(dg).datagrid("loadData", data.slice(start, end));
                        pager.pagination('refresh', {
                            total: data.length,
                            pageNumber: pageNo
                        });
                    }
                });


            }
        }


    </script>
    <script type="text/javascript">
        function DoShowChar(id) {
            $.layer({
                type: 2,
                shadeClose: false,
                title: "承运人详细信息",
                shade: [0.8, '#000'],
                border: [0],
                offset: ['20px', ''],
                area: ['800px', '400px'],
                iframe: { src: 'Net_LinerDetail.aspx?mkey=' + id }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <!--头部信息-->
    <uc2:Net_ControlTop ID="Net_ControlTop1" runat="server" />
    <div id="content">
        <div class="h02">
        </div>
        <!--功能菜单begin-->
        <uc3:Net_ControlMenu ID="Net_ControlMenu1" runat="server" ImgId="13" ImgSrc="images/img-01-2.png" />
        <!--功能菜单end-->
        <div id="content03">
            <div class="boat">
                <div class="h20">
                </div>
                <div>
                    <table>
                        <tr>
                            <td class="text03" width="950">
                                <img src="images/img-03.png" alt="" />
                                &nbsp;&nbsp;&nbsp;班轮船期查询 <a href="#"></a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <img src="images/img-line.png" alt="" class="line" />
                            </td>
                        </tr>
                        <tr>
                            <td height="10">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                    <tr>
                                        <td align="right">
                                            查询方式:
                                        </td>
                                        <td class="xx1">
                                            <asp:DropDownList ID="ddlIE" runat="server" AutoPostBack="TRUE" OnSelectedIndexChanged="ddlIE_SelectedIndexChanged">
                                                <asp:ListItem Value="I" Text="日期"></asp:ListItem>
                                                <asp:ListItem Value="E" Text="船名"></asp:ListItem>
                                            </asp:DropDownList>
                                        </td>
                                        <td align="right" height="50" class="xx1" style="margin-right: 5px">
                                            <div id="DIVDate" runat="server" visible="true">
                                                <ul>
                                                    <li style="list-style: none; float: left; font-size: 16px;">船舶状态:</li>
                                                    <li style="list-style: none; float: left; font-size: 16px;">
                                                        <asp:DropDownList ID="ddlStyles" runat="server" AutoPostBack="TRUE" OnSelectedIndexChanged="ddlStyles_SelectedIndexChanged">
                                                            <asp:ListItem Value="y" Text="预抵"></asp:ListItem>
                                                            <asp:ListItem Value="z" Text="在港"></asp:ListItem>
                                                            <asp:ListItem Value="l" Text="离港"></asp:ListItem>
                                                        </asp:DropDownList>
                                                    </li>
                                                    <li runat="server" id="liLI" visible="false" style="list-style: none; float: left;
                                                        font-size: 16px; margin-right: 1px">离港日期:
                                                        <asp:TextBox ID="txtStart" runat="server" onfocus="WdatePicker({readOnly:true,isShowClear:false})"></asp:TextBox>
                                                        至
                                                        <asp:TextBox ID="txtEnd" runat="server" onfocus="WdatePicker({readOnly:true,isShowClear:false})"></asp:TextBox></li>
                                                </ul>
                                            </div>
                                            <div id="divName" runat="server" visible="false">
                                                <ul>
                                                    <li style="list-style: none; float: left; font-size: 16px;">船名称:</li>
                                                    <li style="list-style: none; float: left; font-size: 16px;">
                                                        <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td class="xx2">
                                            <a href="#">
                                                <img src="images/img-06.png" alt="" name="img06" width="105" height="33" border="0"
                                                    id="img06" onload="" />
                                                <asp:HiddenField ID="hfOption" runat="server" Value="" />
                                            </a>
                                        </td>
                                        <td width="50">
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="h10">
                </div>
                <div style="height: 450px; width: 940px">
                    <table id="dt">
                    </table>
                </div>
                <div class="h05">
                </div>
            </div>
        </div>
    </div>
    <div class="clear h20">
    </div>
    <!--底部信息-->
    <uc1:Net_ControlBottom ID="Net_ControlBottom1" runat="server" />
    </form>
</body>
</html>
</pre><pre code_snippet_id="1733015" snippet_file_name="blog_20160628_4_1752466" name="code" class="html">

杂谈:最近在做接口展示,除了为了加密接口地址,在后台定义webservice方法接收接口数据,之外全是前台的工作。作为一个后台菜鸟,前台一直是我的痛,最难受的是还没美工,只能硬着头皮强上了。不求好看,但求一般的情况下能过眼,还好现在有不少现成的前端框架,学习吧,骚年。。

Loaddata加载本地数据的时候,easyui-datagrid默认的分页不能用,只能手写了。记录下,以后复用

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值