PDA

View Full Version : Hep needed with Customized paging with extjs4



kumar_Rajesh78
3 Apr 2014, 11:05 AM
Dear all,
I understand I can use pageSize and other features to achieve paging. However, I want to be able to write my own paging logic at the server side where in I want to fetch only the records (5 at a time) that I want to display on the page.

When someone clicks on the next button, I want to pass the page size and the row index to the server.
How can I achieve that using extjs 4.

Any help would be highly appreciated.

Thanks,
Rajesh

scottmartin
3 Apr 2014, 11:45 AM
That is how paging works now .. you pagingtoolbar sends the start,limit params to the server and you use that in your SQL statement.

Scott.

kumar_Rajesh78
3 Apr 2014, 12:38 PM
Thanks For the answe Scott. But how would I extract the pagenumber and the page size parameters from the request. This is how I have defined my store. It has a fixed URL without any parameters.

if I click on the next button, it will again call the same fixed URL. Do I need to define the pagesize and page number in a parameter and pass it to server?


proxy: {
type:'ajax',
api: {
read:'../../rest/getBrokerDetails'
},
headers: { 'Content-Type': 'application/json'},
actionMethods: {
read : 'GET'
},
reader: {
type: 'json',
root: 'data'
}
}

scottmartin
3 Apr 2014, 1:31 PM
Have a look at this thread .. see post #8.

I attached an example for paging: f283360.zip
http://www.sencha.com/forum/showthread.php?283360

The toolbar automatically passes the params.


name:Sencha
total:200
page:2
start:15
limit:15

kumar_Rajesh78
3 Apr 2014, 2:13 PM
thanks again Scott,
but I observed that you have define total =100.
Usually, we dont know beforehand, how many total records are going to be there.
it could be 200, 300 depending on the rows returned by the query.
so how do we set this number dynamically.

Thanks,
rajesh

scottmartin
3 Apr 2014, 2:51 PM
You typically would need to issue an additional prepared query to get the count.

Most frameworks provide methods for this as well.

kumar_Rajesh78
3 Apr 2014, 3:31 PM
Hi Scott,
This is not working for me. What I am doing is, I am making a database call and getting only the number of records that is defined in my store definition. In this case, in my database query, I am specifying the number of records to be fetched and the next record number.

But when the records gets displayed in grid, it displayed the 20 records, but it does not enable the next button.
Also it says, displaying 1-20 of 20, instead of 300. What is that I am missing.

This is my store definition.


Ext.define('A.store.B', {
autoLoad: true,
pageSize:20,
proxy: {
type:'ajax',
api: {
read:'../../rest/getBrokerDetails'
},
headers: { 'Content-Type': 'application/json'},
actionMethods: {
read : 'GET'
},
reader: {
type: 'json',
root: 'brokerDetails',
totalProperty: 'total'
},
extraParams : {
total : 300
}
}
});

scottmartin
3 Apr 2014, 3:39 PM
Is this to simulate your total record count?



extraParams : {
total : 300
}


Basically your return json should return the total count (totalProperty) and the 20 records in the json response



{ total: 300, brokerDetails: [{ 20 records }] }


The paging toolbar should see you have a total of 300 in your response and calc the pages.

kumar_Rajesh78
3 Apr 2014, 4:36 PM
Thanks a lot Scott,
I got the point now. Thanks a lot for the explanation.
I added the total in Json response and it started working correctly.

Once again I appreciate all your help.

Thanks,
Rajesh