0

I have a paging toolbar implemented in my grid using extjs 4.1 I get 20 sets of record of first page. "but" when I click next, it does not show the next page. I figure the problem is here

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'
            }

as you can see, the PageNumber I am passing to my controller is static.. If I change that to whatever number I get that page... so how do I get the current page so that I can pass it to my controller.. below is my toolbar

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

please help... thanks

EagleFox
  • 1,367
  • 10
  • 34
  • 58
  • Are you sure that `this` is always your store scope? – sra Nov 20 '12 at 16:16
  • yes sra... please see my reader above.. and also I have the total records showing on the msg.. it says displaying 1-20 of 100... and when I click next it shows 21-40 and page 2, but the grid has the same 20 data from page 1 – EagleFox Nov 20 '12 at 16:30

1 Answers1

1

I'm not sure if I can help you, have you check your backend processing code? I mean, as far as I know, the way you declare store and paging toolbar is right so maybe the problem exist at server side.

for a reference, this is my server side page (remote/data/user/mahasiswa/read.php) to handle store with paging support:

$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).'}';

then, this is my store:

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'
    }
})

finally this is my view:

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);
}
});
Nick Laros
  • 111
  • 2
  • 9
  • 2
    It'd be best to describe the logic of your solution at least briefly. – Serge Belov Nov 21 '12 at 03:05
  • hi Nick... thanks for your reply... i am using c#.. could you please explain your server side code in c#... coz i have no clue on php... and now i see your php code... m sure I have problem with that... could you please help me do what you did on that PHP but on C# – EagleFox Nov 22 '12 at 20:33
  • 1
    I'm sorry @EagleFox .I dont understand C#,but I'll try to explain what I do inside that php code. `$sql="SELECT * FROM user";` query that will be executed to database. `$rs=mysql_query($sql);` execute query. `$totalCount=mysql_num_rows($rs);` get number of record retrieved. `$sql=$sql." LIMIT ".$start.",".$limit;` add page limit param to query. `$rs=mysql_query($sql);` execute query again. `while($obj = mysql_fetch_object($rs)){$arr[] = $obj;}` fetching record then store it inside array. finally `echo '{success:true,totalCount:'.$totalCount.',data:'.json_encode($arr).'}';` format to json – Nick Laros Nov 28 '12 at 12:19
  • Thanks for your explanation Nick... I had a hint there of what you were doing... but trying to implement this in C# is where I am stuck – EagleFox Nov 30 '12 at 19:07