【问题标题】:How to get current page from paging toolbar如何从分页工具栏获取当前页面
【发布时间】:2012-11-08 16:28:55
【问题描述】:

我在我的网格中使用 extjs 4.1 实现了一个分页工具栏,我得到了 20 组第一页记录。 “但是”当我单击下一步时,它不会显示下一页。我想问题就在这里

proxy: {
            type: 'ajax',
            scope: this,
            url: 'Controller/getData',
            extraParams: {
                PageNumber: this.currentPage, // this doesn't change on clicking next
                PageSize: 20

            },
            reader: {
                type: 'json',
                root: 'myTable',
                totalProperty: 'count'
            }

如您所见,我传递给我的控制器的 PageNumber 是静态的。如果我将它更改为我得到该页面的任何数字...那么我如何获取当前页面以便我可以将它传递给我的控制器.. 下面是我的工具栏

bbar: Ext.create('Ext.PagingToolbar', {
            scope: this,
            store: myStore,
            displayInfo: true,
            displayMsg: 'Displaying Records {0} - {1} of {2}',
            emptyMsg: "No Records to display"
        })

请帮忙...谢谢

【问题讨论】:

  • 您确定this 始终是您的商店范围吗?
  • yes sra... 请在上面查看我的读者.. 而且我的总记录显示在 msg 上.. 它说显示 1-20 of 100... 当我单击下一步时显示 21-40 和第 2 页,但网格具有与第 1 页相同的 20 个数据

标签: grid paging toolbar extjs4.1 current-page


【解决方案1】:

我不确定是否可以帮助您,您检查过您的后端处理代码吗?我的意思是,据我所知,您声明存储和分页工具栏的方式是正确的,因此问题可能存在于服务器端。

作为参考,这是我的服务器端页面(remote/data/user/mahasiswa/read.php),用于处理支持分页的存储:

$sql = "SELECT * FROM user";
$rs = mysql_query($sql);
$totalCount = mysql_num_rows($rs);
$sql = $sql." LIMIT ".$start.",".$limit;
$rs = mysql_query($sql);
while($obj = mysql_fetch_object($rs)){
    $arr[] = $obj;
}
echo '{success:true, totalCount:'.$totalCount.', data:'.json_encode($arr).'}';

那么,这是我的商店:

Ext.define('PMK.store.user.Mahasiswa', {
extend: 'Ext.data.Store',
model: 'PMK.model.user.Mahasiswa',
pageSize: 30,

proxy: {
    type: 'ajax',
    url: 'remote/data/user/mahasiswa/read.php',
    reader: {
        type: 'json',
        root: 'data',
        successProperty: 'success',
        totalProperty: 'totalCount'
    }
})

最后这是我的观点:

Ext.define('PMK.view.user.mahasiswa.List' ,{
extend: 'Ext.panel.Panel',
alias : 'widget.mhslist',

title:'Manage Mahasiswa',
layout:'fit',

initComponent: function() {
    this.items = [
        {
            xtype:'grid',
            store:'user.Mahasiswa',
            columns: [
                {xtype: 'rownumberer', width: 50, sortable: false},
                {header: 'Angkatan', dataIndex: 'ANGKATAN', sortable:true, width:60},
                {header: 'NIM', dataIndex: 'NIM', sortable:true, width:100},
                {header: 'Nama', dataIndex: 'NAMA', sortable:true, width:225},
                {header: 'Program Studi', dataIndex: 'PRODI', sortable:true, width:225},
                {header: 'Kelas', dataIndex: 'KELAS', sortable:true, width:50},
                {header: 'Dosen PA', dataIndex: 'DOSEN_PA', sortable:true, width:125},
                {header: 'Jalur', dataIndex: 'JALUR', sortable:true, width:50},
                {header: 'Asal Sekolah', dataIndex: 'ASAL_SEKOLAH', sortable:true, width:175},
                {header: 'Tempat Lahir', dataIndex: 'TL', sortable:true, width:100},
                {header: 'Tanggal Lahir', dataIndex: 'TGL', sortable:true, width:75},
                {header: 'JK', dataIndex: 'JK', sortable:true, width:25},
                {header: 'Alamat', dataIndex: 'ALAMAT', sortable:true, width:225},
                {header: 'Email', dataIndex: 'EMAIL', sortable:true, width:130},
                {header: 'Telp', dataIndex: 'TELP', sortable:true, width:100},
                {header: 'Agama', dataIndex: 'AGAMA', sortable:true, width:50},
                {header: 'Input Date', dataIndex: 'INPUT_DATE', sortable:true, width:125},
                {header: 'Input By', dataIndex: 'INPUT_BY', sortable:true, width:125},
                {header: 'Edit Date', dataIndex: 'EDIT_DATE', sortable:true, width:125},
                {header: 'Edit By', dataIndex: 'EDIT_BY', sortable:true, width:125}
            ]
        }
    ];

    this.bbar = Ext.create('Ext.PagingToolbar', {
        store: 'user.Mahasiswa',
        displayInfo: true,
        displayMsg: 'Displaying mahasiswa {0} - {1} of {2}',
        emptyMsg: "No mahasiswa to display"
    });

    this.callParent(arguments);
}
});

【讨论】:

  • 最好至少简要描述一下您的解决方案的逻辑。
  • 嗨尼克...谢谢您的回复...我正在使用c#..您能否解释一下您在c#中的服务器端代码...因为我对php一无所知...和现在我看到了你的 php 代码......我确定我有问题......你能帮我做你在那个 PHP 上但在 C# 上所做的事情吗
  • 对不起@EagleFox。我不懂C#,但我会试着解释我在那个php代码中做了什么。 $sql="SELECT * FROM user"; 将执行到数据库的查询。 $rs=mysql_query($sql); 执行查询。 $totalCount=mysql_num_rows($rs); 获取检索到的记录数。 $sql=$sql." LIMIT ".$start.",".$limit; 添加页数限制参数进行查询。 $rs=mysql_query($sql); 再次执行查询。 while($obj = mysql_fetch_object($rs)){$arr[] = $obj;} 获取记录然后将其存储在数组中。最后将echo '{success:true,totalCount:'.$totalCount.',data:'.json_encode($arr).'}'; 格式转成json
  • 感谢您的解释,尼克...我暗示了您在做什么...但是尝试在 C# 中实现这一点是我卡住的地方
猜你喜欢
  • 1970-01-01
  • 2010-09-13
  • 1970-01-01
  • 2011-06-17
  • 1970-01-01
  • 2023-02-09
  • 2014-03-22
  • 2010-09-29
  • 2011-05-07
相关资源
最近更新 更多