Extjs实现分页效果

Extjs实现分页还是比较简单的,主要是这套流程弄明白就可以了。(Extjs4.0以后版本适用)

首先js文件需要引入PagingMemoryProxy.js

Ext.Loader.setConfig({ enabled: true });
Ext.Loader.setPath('Ext.ux', '../../../Scripts/ExtJS/ux');
Ext.require([
  'Ext.ux.pagingMemoryProxy.PagingMemoryProxy',
]);

Extjs中引入,当然在HTML页面引入也可以,注意顺序放对就可以了。

定义单页显示记录条数:var itemsPerPage = 20;//单页显示记录条数

在store中添加pageSize和root以及totalProperty

//表格数据源
    var gridStore1 = Ext.create('Ext.data.Store', {
        autoLoad: false,
        fields: ['id', 'stateName', 'ariNumber', 'Tagid', 'FactoryId', 'WorkShopId', 'operator', 'operateTime', 'totalCount'],
        pageSize: itemsPerPage,
        proxy: {
            type: "ajax",
            actionMethods: { read: "POST" },
            url: "CommunicationStatusCFFind.aspx?method=GetCommunicationStatusCFData",
            reader: {
                type: "json",
                root: 'items',
                totalProperty: 'totalProperty'
            }
        }
       
    });

这种方式是通过和C#后台交互返回totalproperty的属性值得。

 var grid1 = Ext.create('Ext.grid.Panel', {
        forceFit: true,
        border: 0,
        store: gridStore1,
        columnLines: true,
        columns: [
            new Ext.grid.RowNumberer(),
            {
                text: 'ID号',
                width: 100,
                dataIndex: 'id',
                field: {
                    xtype: 'textfield'
                }
            },
            {
                text: '通讯状态名称',
                width: 100,
                dataIndex: 'stateName',
                field: {
                    xtype: 'textfield'
                }
            },
            {
                text: '所属车间',
                width: 120,
                dataIndex: 'workShopId'
            },
            {
                header: '工厂名称',
                dataIndex: 'FactoryId',
                align: 'center'
            },
            {
                header: '车间名称',
                dataIndex: 'WorkShopId',
                align: 'center'
            },
            {
                text: '操作人',
                width: 150,
                dataIndex: 'operator',
            },
            {
                text: '操作时间',
                width: 150,
                dataIndex: 'operateTime',
            }
        ],
        dockedItems: [
            {
                xtype: 'toolbar',
                height: 30,
                items: [
                    '<div>-</div>',
                    {
                        xtype: 'combo',
                        labelWidth: 65,
                        labelAlign: 'right',
                        width: 185,
                        id: 'theFactory',
                        fieldLabel: '工厂名称',
                        editable: false,
                        queryMode: 'local',
                        valueField: 'id',
                        displayField: 'AriName',
                        store: FactoryStore
                    },
                    {
                        xtype: 'combo',
                        labelWidth: 65,
                        labelAlign: 'right',
                        width: 185,
                        id: 'theWorkShop',
                        fieldLabel: '车间名称',
                        editable: false,
                        queryMode: 'local',
                        valueField: 'id',
                        displayField: 'AriName',
                        store: WorkShopStore
                    },
                    {
                        xtype: 'combo',
                        labelWidth: 65,
                        labelAlign: 'right',
                        width: 255,
                        id: 'theDevice',
                        fieldLabel: '设备名称',
                        editable: false,
                        queryMode: 'local',
                        valueField: 'id',
                        displayField: 'AriName',
                        store: DeviceStore
                    },
                    '->',
                    {
                        text: '查询',
                        width: 70,
                        handler: function () {
                            var FactoryId = Ext.getCmp("theFactory").getValue();
                            var WorkShopId = Ext.getCmp("theWorkShop").getValue();
                            var DeviceId = Ext.getCmp("theDevice").getValue();
                            var proxy1 = gridStore1.getProxy();
                            proxy1.extraParams = {
                                FactoryId: FactoryId,
                                WorkShopId: WorkShopId,
                                DeviceId: DeviceId
                            };
                            gridStore1.load();
                        }
                    },
                    ' '
                ]
            },
            {
                xtype: 'pagingtoolbar',
                store: gridStore1,   // same store GridPanel is using
                dock: 'bottom',
                displayInfo: true
            }
        ],
        renderTo: Ext.getBody()
    });

在表格grid中的dockeditems中添加分页以及跳转的工具栏

 {
                xtype: 'pagingtoolbar',
                store: gridStore1,   // same store GridPanel is using
                dock: 'bottom',
                displayInfo: true
            }

C#后台获取数据:只需要返回单页的记录条数,不要返回所有的,否则分页效果显示不出来,仍然显示所有的

public void GetCommunicationStatusCFData()
        {
            int enterpriseId = AriMethod.GetEnterpriseId(); //企业Id
            string factoryId = Request["FactoryId"];
            string workShopId = Request["WorkShopId"];
            string DeviceId = Request["DeviceId"];
            string start = Request["start"];
            string limit = Request["limit"];
            List<Model.ModuleHB.CommunicationStatusCF> models = BLL.ModuleHB.CommunicationStatusCFManager.GetAllCommunicationStatusCF(enterpriseId,factoryId,workShopId,DeviceId);

            int totalProperty = models.Count;
            int end = Convert.ToInt32(start) + Convert.ToInt32(limit);
            if (end > totalProperty)
            {
                end = totalProperty;
            }

            DataTable tbl = new DataTable();
            tbl.Columns.Add("id", typeof(String));//id
            tbl.Columns.Add("stateName", typeof(String));//状态名称
            tbl.Columns.Add("ariNumber", typeof(String));//设备编码
            tbl.Columns.Add("Tagid", typeof(String));
            tbl.Columns.Add("FactoryId", typeof(String));
            tbl.Columns.Add("WorkShopId", typeof(String));
            tbl.Columns.Add("operator", typeof(String)); //操作人
            tbl.Columns.Add("operateTime", typeof(String)); //操作时间
            for (int i = Convert.ToInt32(start); i < end; i++)
            {
                DataRow row = tbl.NewRow();
                row["id"] = models[i].AriId;
                row["stateName"] = models[i].StateName;
                if (BLL.ModuleHB.EnvironmentEquCFManager.GetOne(enterpriseId, models[i].AriNumber) != null)
                    row["ariNumber"] = BLL.ModuleHB.EnvironmentEquCFManager.GetOne(enterpriseId, models[i].AriNumber).AriName;
                else
                    row["ariNumber"] = models[i].AriNumber;

                row["Tagid"] = models[i].Tagid;

                if (BLL.ModuleHB.FactoryCFManager.GetOne(enterpriseId, models[i].FactoryId) != null)
                    row["FactoryId"] = BLL.ModuleHB.FactoryCFManager.GetOne(enterpriseId, models[i].FactoryId).AriName;
                else
                    row["FactoryId"] = models[i].FactoryId;

                if (BLL.ModuleHB.WorkSpaceCFManager.GetArinumber(enterpriseId, models[i].WorkShopId) != null)
                    row["WorkShopId"] = BLL.ModuleHB.WorkSpaceCFManager.GetArinumber(enterpriseId, models[i].WorkShopId).AriName;
                else
                    row["WorkShopId"] = models[i].WorkShopId;

                row["operator"] = models[i].Operator;
                row["operateTime"] = models[i].OperateTime;
                tbl.Rows.Add(row);
            }

            string json = JSON.Encode(tbl);
            json = "{'items':" + json + "," + "'totalProperty':" + totalProperty + "}";
            Response.Write(json);
            Response.End();
        }

其中start和limit参数不需要在前端定义,这应该是PagingMemoryProxy中有的参数,在后台直接Request获取即可。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

雨中深巷的油纸伞

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

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

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

打赏作者

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

抵扣说明:

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

余额充值