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、定义按钮点击事件:

//点击查找按钮出发事件
        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));

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奋斗---现在进行时

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值