zoukankan      html  css  js  c++  java
  • Asp.Net MVC EasyUI DataGrid查询分页

    function doSearch() {
           //查询方法
            var searchValue = $('#txtQueryTC001').textbox('getText');
            $('#dgCMSTC').datagrid('options').queryParams = { condition: searchValue };
            //initDataGrid(searchValue);
            $.ajax({
                type: 'post',
                url: '/CMSTC/GetJson',
                data: 'condition=' + searchValue,
                dataType: 'json',
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.alert("查询数据", "发生错误!" + errorThrown, "error");
                },
                success: function (data) {
                    console.info(data);
                    //$.messager.alert('数据', JSON.stringify(data), 'info');
                    $('#dgCMSTC').datagrid('load', []);
                    $('#dgCMSTC').datagrid('load', data);
     
                    //initDataGrid(searchValue);
                }
            });
        }
     
    $(function () {
            //初始化datagrid
            $('#dgCMSTC').datagrid({
                method: 'post',
                url: '/CMSTC/GetJson',
                singleSelect: true,
                fit: true,
                border: true,
                pagination: true,
                pageSize: 20,
                queryParams: { condition: '' },
                columns: [[
                        { field: 'TC001', title: '仓库编号',  100 },
                        { field: 'TC002', title: '仓库名称',  100 },
                        { field: 'TC003', title: '仓库电话',  100 },
                        { field: 'CREATOR', title: '创建者',  100 },
                        { field: 'CREATE_DATE', title: '创建日期',  100 },
                        { field: 'MODIFIER', title: '修改者',  100 },
                        { field: 'MODI_DATE', title: '修改日期',  100 }
                    ]],
                toolbar: '#toolQuery',
                onLoadSuccess: function (data) {
                    if (data.total > 0) {
                        $('#dgCMSTC').datagrid('selectRow', 0);
                    }
                }
            });
    });
     
    <a id="btnSearch" href="#" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="doSearch();">Search</a>

    后台代码:

    复制代码
    public JsonResult GetJson()
            {
                using (var myDb = new studydb<CMSTC>(strConn))
                {
                    string strCondition = Request.Form["condition"];
                    int page = 1;
                    int rows = 20;
                    List<CMSTC> myCMSTC;
                    List<CMSTC> myCMSTCPAGE;
                    if (Request.Form["page"]!=null) {
                        page = Convert.ToInt32(Request.Form["page"].ToString());  
                    }
                    if (Request.Form["rows"] != null)
                    {
                        rows = Convert.ToInt32(Request.Form["rows"].ToString());
                    }
                    if (string.IsNullOrEmpty(strCondition))
                    {
                        myCMSTC = myDb.CMSTC.ToList();       //查询数据都是正确的
                        myCMSTCPAGE = myDb.CMSTC.OrderBy(i => i.TC001).Skip((page - 1) * rows).Take(rows).ToList();
                    }
                    else
                    {
                         myCMSTC = myDb.CMSTC.Where(p => p.TC001.Contains(strCondition) || p.TC002.Contains(strCondition)).ToList();       //查询数据都是正确的
                         myCMSTCPAGE = myDb.CMSTC.OrderBy(i => i.TC001).Where(p => p.TC001.Contains(strCondition) || p.TC002.Contains(strCondition)).Skip((page - 1) * rows).Take(rows).ToList();
                    }
                    return Json(new { total = myCMSTC.Count, rows = myCMSTCPAGE }, JsonRequestBehavior.AllowGet);
     
                }
            }
    复制代码

    我在webform里都是这样写的,但是换到mvc里就有问题了,主要是查询完了加载本地数据的地候,主要是这句:
    $('#dgCMSTC').datagrid('load', []);
     $('#dgCMSTC').datagrid('load', data);

  • 相关阅读:
    关于MySQL与SQLLite的Group By排序原理的差别
    利用Java针对MySql封装的jdbc框架类 JdbcUtils 完整实现(包括增删改查、JavaBean反射原理,附源代码)
    深入java并发Lock一
    windows 7 SDK和DDK下载地址
    用cocos2d-x 3.2 实现的FlappyBird
    Java替代C语言的可能性
    Spring Quartz结合Spring mail定期发送邮件
    web小流量实验方案
    paip.微信菜单直接跳转url和获取openid流程总结
    【java web】java运行预编译Groovy脚本
  • 原文地址:https://www.cnblogs.com/huangf714/p/5864405.html
Copyright © 2011-2022 走看看