PDA

View Full Version : Force Store to reload though it's empty?



fletchergirl
8 Mar 2011, 1:42 AM
Good morning!

Sorry if this question seems stupid to you, but I don't know how to solve this... :-?
I have a drag and drop grid that shows 'possible userrights' and 'assigned userrights'. Works fine so far but if a user has no 'assigned rights', the store just doesn't reload (obviously because it's empty?!) and the userrights of the last user stay in the grid.
Is there a way to force this store to reload?
I'm stuck! :((
Here's the code:
(on dblclick CCU-Grid, AssignedNotifsStore is reloading)


// CCU-GRID /////////////////////////////////////////////////////

var ccuGrid = new Ext.grid.GridPanel({
id : 'CCUTable',
height: 200,
title : 'Assign Macro-projects and Notifications',
clicksToEdit : 2,
flex: 1,
store : combinationStore,
sm: new Ext.grid.RowSelectionModel(),
columns : [{
header : 'CCU_ID',
dataIndex : 'CCU_ID',
width : .08,
sortable : true,
editor : {
xtype : 'numberfield',
allowBlank : false
}
},{
header : 'Combine',
dataIndex : 'NAME',
width : .08,
sortable : true,
editor : {
xtype : 'textfield',
allowBlank : false
}
},{
header : 'Country',
dataIndex : 'NAME_ENGLISH',
width : .12,
sortable : true,
editor : {
xtype : 'textfield',
allowBlank : true
}
}],
tbar: new Ext.Toolbar({
height: 30,
items: [
{
xtype: 'tbfill'
},
{
text: 'Show choice',
icon : 'images/branch_add.png',
cls : 'x-btn-text-icon',
id: 'showCCU',
handler: ButtonClick
}]
}),
view : new Ext.grid.GroupingView({
autoFill : true,
forceFit : true,
startCollapsed : true,
showGroupName : true,
enableNoGroups : false,
enableGrouping : true,
enableGroupingMenu : true,
hideGroupedColumn : false,
markDirty : false,
columnsText : 'Spalten ein/ausblenden',
groupByText : 'Gruppieren nach dieser',
showGroupsText : 'Gruppierung ein/ausschalten',
sortAscText : 'Aufsteigend Sortieren',
sortDescText : 'Absteigend Sortieren'
}),
listeners:{
'dblclick':{
fn: function() {
var current_CCU_ID = Ext.getCmp('CCUTable').getSelectionModel().getSelections();
var CCUCount = Ext.getCmp('CCUTable').getSelectionModel().getCount();
var CCUArray = '';
for (i=0;i<CCUCount;i++){
if (i<CCUCount-1){
CCUArray = CCUArray+current_CCU_ID[i].data.CCU_ID+',';
}else{
CCUArray = CCUArray+current_CCU_ID[i].data.CCU_ID;
}
}


//Store laden
AssignedNotifsStore.load({params: {currentCCUArray:CCUArray}});
NotAssignedNotifsStore.load({params: {currentCCUArray:CCUArray}});
}
}
}
});

// ++++++++++++ Assign Notifications to user +++++++++++++++
var fieldsNotifDrDr = ['NOT_ID','NOTIFICATION_TYPE','SEND_TYPE','NCO_ID','NAME'];

// used to add records to the destination stores
var blankoRecord2 = Ext.data.Record.create(fieldsNotifDrDr);

// column model object
var cols2 = [
{dateIndex: 'NOT_ID', header: 'NOT_ID', hidden: true},
{header: "Notification" , width: 300, dataIndex: 'NOTIFICATION_TYPE'},
{header: "Instant", width:80 ,dataIndex: 'SEND_TYPE'},
{dateIndex: 'NCO_ID', header: 'NCO_ID', hidden: true},
{dateIndex: 'NAME', header: 'NAME', hidden: true}
];

// zugewiesene Rechte
var assignedNOTGrid = new Ext.grid.EditorGridPanel({
ddGroup : 'secondGridDDGroup2',
id : 'Notifics',
store : AssignedNotifsStore,
flex : 1,
cm : new Ext.grid.ColumnModel({
defaults:{
sortable: true,
editable: true
},
columns: cols2}),
view : new Ext.grid.GridView({
sortAscText : 'Aufsteigend Sortieren',
sortDescText : 'Absteigend Sortieren',
columnsText: 'Spalten'
}),
enableDragDrop : true,
stripeRows : true,
title : 'Assigned Notifications',
listeners: {
afterrender: {
fn: function() {
// This will make sure we only drop to the view scroller element
firstGridDropTargetEl2 = assignedNOTGrid.getView().scroller.dom;
firstGridDropTarget2 = new Ext.dd.DropTarget(firstGridDropTargetEl2, {
ddGroup : 'firstGridDDGroup2',
notifyDrop : function(ddSource, e, data){
var records = ddSource.dragData.selections;
Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
assignedNOTGrid.store.add(records);
assignedNOTGrid.store.sort('NAME', 'ASC');
return true
}
});
}
},
render: function() {
// After the component has been rendered, disable the default browser context menu
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
},
contextmenu: function(e) {
if (!this.contextMenu) {
this.contextMenu = new Ext.menu.Menu({
shadow: 'drop',
id: 'gridNOTMenu',
items: [{
text: 'Copy selected rows',
iconCls : 'insert-icon',
id: 'copySel',
icon: 'images/copy.png',
handler: ButtonClick
},
'-',
{
text: 'Copy all',
iconCls : 'insert-icon',
id: 'copyAll',
icon: 'images/copy.png',
handler: ButtonClick
},
'-',
{
text: 'Paste',
iconCls : 'paste-icon',
id: 'pasteAll',
icon: 'images/document_into.png',
handler: ButtonClick,
disabled: true
}
]

});
}
var xy = e.getXY();
this.contextMenu.showAt(xy);
}
}
});

// noch nicht zugewiesene Rechte
var notAssignedNOTGrid = new Ext.grid.EditorGridPanel({
ddGroup : 'firstGridDDGroup2',
store : NotAssignedNotifsStore,
flex : 1,
cm : new Ext.grid.ColumnModel({
defaults:{
sortable: true,
editable: true
},
columns: cols2}),
view : new Ext.grid.GridView({
sortAscText : 'Aufsteigend Sortieren',
sortDescText : 'Absteigend Sortieren',
columnsText: 'Spalten'
}),
enableDragDrop : true,
stripeRows : true,
plugins : [userRoleFilter],
title : 'Not yet assigned Roles',
listeners: {
afterrender: {
fn: function() {
// This will make sure we only drop to the view scroller element
secondGridDropTargetEl2 = notAssignedNOTGrid.getView().scroller.dom;
secondGridDropTarget2 = new Ext.dd.DropTarget(secondGridDropTargetEl2, {
ddGroup : 'secondGridDDGroup2',
notifyDrop : function(ddSource, e, data){
var records = ddSource.dragData.selections;
Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
notAssignedNOTGrid.store.add(records);
notAssignedNOTGrid.store.sort('NAME', 'ASC');
return true
}
});
}
}
}
});

mitchellsimoens
8 Mar 2011, 4:26 AM
Stores have a reload method:


store.reload();

Look at the API docs for the config options you can pass in the reload method.

fletchergirl
8 Mar 2011, 11:35 AM
Thanx for your answer Mitchell, but I need to load the store each time with a different ID so reload() would not work here.

mitchellsimoens
8 Mar 2011, 11:36 AM
Sure it would...


//keeps other params
store.reload({
params : {
id : 1
}
});
//dumps other params except baseParams or extraParams
store.load({
params : {
id : 1
}
});

fletchergirl
9 Mar 2011, 1:04 AM
Thanx for your effort Mitchell. That wasn't the problem but a mistake in the PHP. I have to give back rows: [] when there's no dataset in the db.

hajix
13 Aug 2014, 3:31 PM
And is there any way to force reload of a specific page, even if it is loaded already? store.loadPage(index) tries to fetch a page before the index to accommodate for leading buffer zone, and then skips loading index-th page because it is already loaded.

I.e. to call store.loadPage(3), will make a server call to load page 2, and after it comes back since total count is equal to count, it skips fetching page #3.