简体   繁体   English

C#网格分页和ExtJS 4.1

[英]C# Grid Paging and ExtJS 4.1

I am trying to implement paging toolbar on extjs grid pangel using c# backend... How do I start doing about that... I have tried using start and limit but I am not sure how it works. 我正在尝试使用c#后端在extjs网格pangel上实现分页工具栏...我该如何开始...我尝试使用开始和限制,但是我不确定它是如何工作的。 could someone please help me on how I can just send about 20 records per page in the grid, because my grid is getting all 500 datas, which is slowing my application as well below is my controller that sends json to my store.. Please help 有人可以帮我解决一下,如何在网格中每页发送大约20条记录,因为我的网格正在获取所有500个数据,这也减慢了我的应用程序的速度,下面是我的控制器,它向我的商店发送json。

 public JsonResult getData(int start, int limit)
 {
   List<MyItem> items = new List<MyItem>();
   using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices1"].ConnectionString))
   {
     SqlCommand cmd = con.CreateCommand();
     cmd.CommandText = "SELECT State, Capital FROM MYDBTABLE";
     con.Open();
     SqlDataReader reader = cmd.ExecuteReader();
     while (reader.Read())
     {
       MyItem item = new MyItem();
       item.State = reader[0].ToString(); 
       item.Capital = reader[1].ToString(); 
       items.Add(item);
     }
     con.Close();

     return Json(new {  myTable = items }, JsonRequestBehavior.AllowGet);
   }
}

and this is my store 这是我的商店

this.store = Ext.create('Ext.data.JsonStore', {
        autoLoad: true,
        storeId: 'mystore1',
        pageSize: 20,
        fields: [
    { name: 'State' },
    { name: 'Capital' } 
    ],
        sorters: [
            {
                property: 'State',
                direct: 'ASC'
            }],
        scope: this,
        proxy: {
            type: 'ajax',
            scope: this,
            url: 'StateC/getData',
            autoLoad: { params: {
                start: 0,
                limit: 20
            }
            },
            reader: {
                type: 'json',
                root: 'myTable'
            }
        }
    });

I'm currently using MySQL & PHP so definitely error check my syntax on this, but the general logic is similar, however the syntax is a little more vague in MsSQL for the query. 我目前正在使用MySQL和PHP,因此肯定会在此方面检查我的语法,但是一般逻辑是相似的,但是在MsSQL中查询的语法有些模糊。 I would suggest this link for the a primer on the MsSQL recomended syntax: 我建议使用此链接作为MsSQL推荐语法的入门:

http://www.codeguru.com/csharp/.net/net_data/article.php/c19611/Paging-in-SQL-Server-2005.htm http://www.codeguru.com/csharp/.net/net_data/article.php/c19611/Paging-in-SQL-Server-2005.htm

First you need to get the parameters that are passed by extjs on the ajax calls: 首先,您需要获取ajax调用中extjs传递的参数:

int limit = Request.QueryString["limit"];
int page= Request.QueryString["page"];
int upperBound = limit * page;
int lowerBound = limit * (page - 1) + 1;

I think that should work out to something like this for your query as well: 我认为对于您的查询也应该解决类似这样的问题:

SELECT * FROM (
        SELECT 
            ROW_NUMBER() OVER(ORDER BY person) AS rownum, 
            MYDBTABLE.State, 
            MYDBTABLE.Capital 
        FROM MYDBTABLE
    ) AS States
WHERE  States.rownum >= {lowerBound} AND States.rownum <= {upperBound}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM