PDA

View Full Version : how applystate works?



wlpanzy
4 Dec 2014, 6:18 AM
i used the default object cookieProvider?but i found a problem?the method applyState can work on IE?but can't work on chrome?
i can't call applyState on chrome?so the cookie can not work?any problem in my code?


Ext.ns('App.cashremit.qshkgl');var columnsView;
App.cashremit.qshkgl.QshkglGrid = Ext.extend(App.ux.SysGridPanel, {
columns : [],
constructor : function(config) {
this.store = new Ext.data.DirectStore({
directFn : qshkglAction.queryQshksq,
paramsAsHash : true,
autoDestroy : true,
remoteSort : true,
fields : []
});
Ext.apply(config, {
store : this.store,
enableColumnMove : true,
stateful : true,
stateId : 'QshkglGrid',
initStateEvents : function() {
Ext.grid.GridPanel.superclass.initStateEvents.call(this);
this.colModel.on("configchange",this.applyStateAfter, this, {
delay : 100
});
},
getState : function() {
var o = {
columns : []
};
for ( var i = 0, c; c = this.colModel.config[i]; i++) {
o.columns[i] = {
dataIndex : c.dataIndex,
width : c.width,
id:c.id,
sort:i
};
if (c.hidden) {
o.columns[i].hidden = true;
}
}
return o;
},
applyState : function(state) {
alert("applyState");
columnsView = state.columns;
Ext.grid.GridPanel.superclass.applyState.call(this, state);
},
applyStateAfter : function(columnModel) {
var cm = this.colModel;
var cs = columnsView;
if (cs) {
for ( var i = 0, len = cs.length; i < len; i++) {
var s = cs[i];
var c = cm.getColumnById(s.id);
if (c) {
c.hidden = s.hidden;
c.width = s.width;
var oldIndex = cm.getIndexById(s.id);
if (oldIndex != i) {
cm.moveColumn(oldIndex, i);
}
}
}
}
this.reconfigure(this.store, cm);
}
});
App.cashremit.qshkgl.QshkglGrid.superclass.constructor.call(this,
config);
},
viewConfig : {
emptyText : "????",
onDataChange : function() {9
if (this.cm.getColumnCount() == 0
&& this.ds.reader.jsonData.metaData.columns) {
columns = this.ds.reader.jsonData.metaData.columns;
if (this.grid.checkboxSelect) {
columns = [].concat(this.grid.selModel).concat(columns);
}
this.cm.setConfig(columns);
this.syncFocusEl(0);
return;
}
this.refresh();
this.updateHeaderSortState();
this.syncFocusEl(0);
}
}
});


Ext.reg('QshkglGrid', App.cashremit.qshkgl.QshkglGrid);

wlpanzy
4 Dec 2014, 5:46 PM
i add the method initState,copy the default code,that i found it doesn't work either.i saw initState is used in component.js.why it doesn't work on chrome and firefox but work on ie right?
initState : function(){ if(Ext.state.Manager){
var id = this.getStateId();
if(id){
var state = Ext.state.Manager.get(id);
if(state){
if(this.fireEvent('beforestaterestore',this,state) != false){
this.applyState(Ext.apply({},state));
this.fireEvent('staterestore',this,state);
}
}
}
}
}