PDA

View Full Version : Newbie need help!!!



choncona1
13 Sep 2010, 9:29 PM
I know this is a newbie's question, but I am really bumping my head with it.
I have a page with the button that will load data to a grid.
The grid's columns are sortable. The data is ordered from database.
From the UI, clients are able to sort data by themselves.
Now, the requirements is that every time clicking the upper "refresh" button
it shall reload the data with the order from database.
But it seems doesn't work out for me since it keeps the remain sorting order from the UI.
This is my method to solve the problem

listeners: {
click: function() {
storeEG.load();
Ext.getCmp('tempField').removeAll(true);
Ext.getCmp('tempField').add(new Ext.grid.GridPanel({
id: 'display',
store: storeEG,
cm: colModel
}));
resizing();
Ext.getCmp('tempField').doLayout();
}
}
If you have any problems reading my code, please let me know.
I simply create a 'fielset', then removing everything before reloading.
Please spend kindly assist me with this problem.
Thank you very much

Condor
14 Sep 2010, 12:16 AM
I assume that your store is not configured with remoteSort:true?

In that case you simply need to remove the sortInfo (or multiSortInfo), e.g.

delete store.sortInfo;
store.load();

choncona1
14 Sep 2010, 12:46 AM
I assume that your store is not configured with remoteSort:true?

In that case you simply need to remove the sortInfo (or multiSortInfo), e.g.

delete store.sortInfo;
store.load();

hi, Condor
Thank you for your quick reply,
I haven't tried to remove the sortInfo
but I configured the remoteSort:true as you had mentioned
the result from that is when the client sort manually,it doesn't turn out as the normal way
Would you mind giving me a short explanation on how does this work out?
I am really appreciated for your time.

Condor
14 Sep 2010, 1:05 AM
A store has 2 sort modes, local and remote.

1. In local mode the store uses the sortInfo (or multiSortInfo) to sort the data itself.
2. In remote mode the store sends 'sort' and 'dir' parameters with the load and expects the server to return the records in the correct order.

It looks like you want local mode (remoteSort:false), but you want to remove the sortInfo before loading.

choncona1
14 Sep 2010, 1:13 AM
thanks,
Just another question, is there anything like "store.sortInfo.remove"?
I am finding it for a while but couldn't get any hints.

Condor
14 Sep 2010, 1:27 AM
Didn't you look at post #2?

choncona1
14 Sep 2010, 1:37 AM
sorry, my bad
but even i tried something like below as in my code

delete storeEG.sortInfo;
storeEG.load();
the refreshed-again-result still doesn't come out as same as database after the manual sorting
sorry for my bad English if it sound vague

Condor
14 Sep 2010, 1:40 AM
1. Is storeEg a normal Store or a GroupingStore?
2. Is your server sending metaData with sortInfo together with the data?

choncona1
14 Sep 2010, 1:50 AM
1/It is the normal store. this is how i wrote the store

var storeEG=new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ method: 'post',url: 'rPages/rEgsitting.aspx?m=egcomb' })
,reader: gridJson
});
2/Not really sure about the term "metaData", but the sortInfo does come together with the data since the store procedure
from DB write "ORDER BY..."

Condor
14 Sep 2010, 2:21 AM
If you don't know what metaData is then you are definately not using it.

Strange... In that case this should really work:

delete storeEG.sortInfo;
delete storeEG.multiSortInfo;
storeEG.load();

choncona1
14 Sep 2010, 2:31 AM
thanks for the replies, but that one doesn't work out either
I tried to refresh the whole page and, awkwardly, it temporary solved the problem
have a nice day:)

Condor
14 Sep 2010, 2:36 AM
Are you using an Ext.state.Manager? In that case you might want to configure the grid with stateful:false.

choncona1
14 Sep 2010, 2:41 AM
No, my code is just as simple as my Ext knowledge:P
a refresh button and a sortable grid

choncona1
14 Sep 2010, 2:43 AM
No, my code is just as simple as my Ext knowledge:P
a refresh button and a sortable grid

Condor
14 Sep 2010, 2:44 AM
Can you post your current code?

choncona1
14 Sep 2010, 2:49 AM
here you go, it is a little messy

Ext.BLANK_IMAGE_URL='../JS/extJS/resources/images/default/s.gif';
Ext.onReady(function() {
gridJson=new Ext.data.JsonReader({
root: 'rootGridJ',
totalProperty: 'totalGridJ',
id: 'Egsitting'
},[
{ name: 'TableId' },
{ name: 'SeatId' },
{ name: 'UserId' },
{ name: 'UserName' },
{ name: 'NickName' },
{ name: 'IP' },
{ name: 'CountRS' }
]);
var storeEG=new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ method: 'post',url: 'rPages/rEgsitting.aspx?m=egcomb' })
,reader: gridJson
});

var colModel=new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer({width: 30}),
{ header: 'Table',dataIndex: 'TableId',width: 55,sortable: true },
{ header: 'Seat',dataIndex: 'SeatId',width: 55,sortable: true },
{ header: 'IP Address',dataIndex: 'IP',width: 100,sortable: true },
{ header: 'User Name',dataIndex: 'UserName',width: 85,sortable: true },
{ header: 'Nick Name',dataIndex: 'NickName',width: 100,sortable: true }
]);
var EGpanel=new Ext.FormPanel({
id: 'mainForm',
title: 'e-Games Sitting',
frame: true,
renderTo: Ext.getBody(),
width: 225,
items: [{
xtype: 'button',
text: 'Refresh',
Refresh: true,
style: 'margin-bottom:15px',
listeners: {
click: function() {
delete storeEG.sortInfo;
delete storeEG.multiSortInfo;
storeEG.load();
Ext.getCmp('tempField').removeAll(true);
Ext.getCmp('tempField').add(new Ext.grid.GridPanel({
id: 'display',
store: storeEG,
cm: colModel
}));
resizing();
Ext.getCmp('tempField').doLayout();
}
}
},{
xtype: 'fieldset',
id: 'tempField'
}]
});
Ext.EventManager.onWindowResize(function() { resizing(); });
//resizing();
Ext.get('loading-mask').hide({
duration: 1,
opacity: 0,
callback: function() {
$('div#loading-mask').remove();
}
});
})
function resizing()
{
Ext.getCmp('mainForm').setWidth(Ext.getBody().getViewSize().width);
Ext.getCmp('mainForm').setHeight(Ext.getBody().getViewSize().height);
Ext.getCmp('display').setWidth(Ext.getBody().getViewSize().width-50);
Ext.getCmp('display').setHeight(Ext.getBody().getViewSize().height-200);
}

Condor
14 Sep 2010, 3:30 AM
1. Why are you using your own resizing logic instead of using an Ext.Viewport?
2. Why are you destroying and recreating the grid everytime you click the Refresh button?

choncona1
14 Sep 2010, 6:31 PM
sorry for my late reply.I have gone home before your message arrived
1/The resizing method has been using by my seniors previously.And they taught me that way. As mentioned from above, I am a newbie
2/Because I thought it will return back the same data ordering from DB if you create a new of it. That what I had in my mind