Asp.Net MVC EasyUI DataGrid查詢分頁

來源:互聯網
上載者:User

標籤:

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: ‘倉庫編號‘, width: 100 },                    { field: ‘TC002‘, title: ‘倉庫名稱‘, width: 100 },                    { field: ‘TC003‘, title: ‘倉庫電話‘, width: 100 },                    { field: ‘CREATOR‘, title: ‘建立者‘, width: 100 },                    { field: ‘CREATE_DATE‘, title: ‘建立日期‘, width: 100 },                    { field: ‘MODIFIER‘, title: ‘修改者‘, width: 100 },                    { field: ‘MODI_DATE‘, title: ‘修改日期‘, width: 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);

Asp.Net MVC EasyUI DataGrid查詢分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.