PDA

View Full Version : GridPanel limit results



ultraman69
7 Sep 2010, 12:12 PM
Hi !

I just can't figure out what's wrong. I just can't make my data store returns just the number of row that I need... I tried a few options, but none of them works, it always gives me the full resultset.

Do I have to do something on server-side (in my WCF service) ?



Ext.onReady(function() {

var personne = Ext.data.Record.create([
{ name: 'nom' },
{ name: 'prenom' }
]);

var myReader = new Ext.data.JsonReader({
totalProperty: "total",
root: "list"

}, personne
);

var myProxy = new Ext.data.HttpProxy({
url: 'http://localhost:1041/Person.svc/Get',
method: 'POST'
//params: {}
});

var store = new Ext.data.Store(
{
proxy: myProxy,
reader: myReader

}
);

var pagingToolbar = {
xtype: 'paging',
store: store,
pageSize: 5,
displayInfo: true
}

var gr = new Ext.grid.GridPanel({
el: 'grid', //div dans la quelle le GridPanel sera dessiné
viewConfig: { //Fait en sorte que la somme des largeurs de colonnes soit égale à la taille de la grille
forceFit: true
},
ds: store, // la source de données
bbar: pagingToolbar,
cm: new Ext.grid.ColumnModel([ //Définit les colonnes du tableau et le mapping avec les champ du Record
{header: "Nom", width: 120, sortable: true, dataIndex: 'nom' },
{ header: "Prenom", width: 100, sortable: true, dataIndex: 'prenom' }
]),
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }), // Politique de séléction de ligne (Sélection simple)
width: 600, //largeur de la grille
height: 300, //hauteur de la grille
frame: true, //dessine la grille avec un contour arrondit
title: 'Grid Panel Example' //titre de la grille

});

//Afficher la grille
gr.render();
//Charger les données
store.load({});
// store.load({ // 2
// params: {
// start: 0,
// limit: 5
// }
// });

});

Condor
8 Sep 2010, 12:22 AM
You are using remote paging, so Ext expects the server to return the correct records for the specified 'start' and 'limit' parameters.

ps. If you want local paging then you should use the PagingStore user extension.

ultraman69
8 Sep 2010, 6:07 AM
Ok, thanks ! Now I just have to understand how to pass parameters to a .NET WCF service... Tried everything, but nothing seems to work. Not even if I just try the start and limit parameters...

Thanks a lot !

darthwes
8 Sep 2010, 10:49 AM
Add this to your store definition?



new Ext.data.Store({
...
baseParams: {
'start': '',
'limit': '5'
},
...
})

Condor
8 Sep 2010, 9:39 PM
No, that is wrong.

start and limit (and sort and dir) shouldn't be in baseParams. For paging, any other param should indeed go into baseParams.

For start and limit you should use:

autoLoad: {params: {start: 0, limit: 5}}
or simply

store.load({params: {start: 0, limit: 5}});

darthwes
9 Sep 2010, 12:55 PM
@Condor: What makes it wrong? store.load(); seems quicker to write, read, and maintain than store.load({params: {start: 0, limit: 5}}); I'm not trying to pick, I am concerned that my projects are going to fall victim to something I didn't consider before (that my baseParams aren't working properly).

steffenk
9 Sep 2010, 2:06 PM
i don't get it too. You even can override baseParams with params in load call if you want. At the end it's merged

Ext.applyIf(options.params, this.baseParams);

Condor
9 Sep 2010, 9:50 PM
Yes, it works, but IMHO 'dynamic' parameters like 'start', 'limit', 'sort' and 'dir' don't belong in the 'static' baseParams.