zoukankan      html  css  js  c++  java
  • EasyUi 中datagrid 实现查询方法

    1、在初始化表格方法中添加传入參数,例如以下:

     //初始化表格
            function initTable(<strong><span style="color:#ff6666;">params</span></strong>) {
                $('#test').datagrid({
                    title: '客户列表',
                    iconCls: 'icon-Custom',
                    loadMsg: '数据载入中...',
                    nowrap: true,
                    autoRowHeight: true,
                    striped: true,
                    url: '/CustomManager/GetAllCustomInfo',
                    sortName: 'CID',
                    sortOrder: 'asc',
                    border: true,
                    remoteSort: false,
                    idField: 'CID',
                    pageSize: 10,
                    pagination: true,
                    rownumbers: true,
                    <span style="color:#ff6666;"><strong>queryParams: params, //搜索json</strong></span>

    2、定义button点击事件:

    //点击查找button出发事件
            function searchFunc() {
                initTable(initQuery());
            }

    3、获取查询对象。转换为json对象

     //表单查询值组成json对象
            function initQuery() {
                var queryParams = {
                    ShopName: $('#ShopName').val(),
                    PerName: $('#PerName').val() //须要查询的对象
                };
                return queryParams;
            }

    4、后台datagrid的绑定事件中接收參数,进行查询

    public ActionResult GetAllCustomInfo(T_Custom model)
            {
                int pageIndex = Request["page"] == null ? 1 : int.Parse(Request["page"]);
                int pageSize = Request["rows"] == null ? 10 : int.Parse(Request["rows"]);
                int total = 0;
                var temp = from u in db.T_Custom
                           select u;

    //推断參数
                if (!string.IsNullOrEmpty(model.ShopName))
                    temp = temp.Where(b => b.ShopName.Contains(model.ShopName));
                if (!string.IsNullOrEmpty(model.PerName))
                    temp = temp.Where(b => b.PerName.Contains(model.PerName));

  • 相关阅读:
    P2426 删数
    P2115 [USACO14MAR]破坏Sabotage
    P2679 子串
    P2979 [USACO10JAN]奶酪塔Cheese Towers
    P1114 “非常男女”计划
    P2105 K皇后
    P4053 [JSOI2007]建筑抢修
    P1294 高手去散步
    P4316 绿豆蛙的归宿
    P2253 好一个一中腰鼓!
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5189079.html
Copyright © 2011-2022 走看看