问题
I'm having some problems with combobox for selecting items from database. Since more than 100 items are loaded, I use paging toolbar at bottom of combobox. Now if pages size is set to 5 or 50, the paging toolbar shows page 1 of 20 or 1 of 2 depending on pagesize, but combobox shows all 100 items, and just copy them to next page like page size is not set at all. I tried several thing but nothing seems to make it work. What's wrong?
{
xtype: 'combobox',
queryMode: 'local',
valueField: 'id',
fieldLabel: 'Description SKU',
name: 'id_fk',
pageSize: 5,
width: 400,
padding: 5,
store: Ext.create('Ext.data.Store',
{
fields: ['id','key item','description'],
autoLoad: true,
pageSize: 5,
proxy:
{
type: 'ajax',
url: 'items/load',
reader:
{
type: 'json',
root: 'data'
}
}
}),
tpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'<div class="x-boundlist-item">{key item} - {description}</div>',
'</tpl>'),
displayTpl: Ext.create('Ext.XTemplate',
'<tpl for=".">',
'{key item} - {description}',
'</tpl>'
)
}
回答1:
When the request is made to load the store, it will pass a pageSize query parameter with value 5.
However, it is up to your server-side services to take this parameter into account when returning results.
EDIT: Here's an example of paging combobox: http://docs.sencha.com/extjs/4.1.3/#!/example/form/forum-search.html
If you open the network tab on your web development console, you will see the request being fired and you can look at the query parameters. You can send others as necessary, but this should be more than enough for basic paging.
The following are the query parameters sent:
limit - set by the "pageSize" parameter (default of 25)
start - the first record to be returned (starts at 0 and is incremented by pageSize using the prev/next buttons on the toolbar)
page - the page we are on (starts at 1 and is decremented/incremented by 1 using the prev/next buttons on the toolbar)
query - the text in the combobox.
EDIT 2: You should also be returning a "totalProperty" in your response from your server which has the total number of results. This will update the toolbar appropriately (e.g you are on page x of y). By default, the totalProperty expected is "total". You can see this when you look at the code in the example provided.
来源:https://stackoverflow.com/questions/29398495/combobox-paging-toolbar-doesnt-respond-to-page-size