Amit Shrestha

Posts Tagged ‘stateful example

http://xtrace.blogspot.com/2011/09/stateful-example-in-extjs-saving-tree.html  [Migrating to this blog,,flollow there for further updates]

More on extjs at: http://xtrace.blogspot.com/search/label/extjs

First read this:  http://dev.sencha.com/deploy/ext-4.0.2a/docs/#/api/Ext.state.Stateful-cfg-stateful

Following example demonstrate simple way to save a selected item in tree:

  1. this.tree = Ext.create(‘Ext.tree.Panel’, {
  2.     viewConfig: {
  3.         plugins: {
  4.             ptype: ‘treeviewdragdrop’,
  5.             appendOnly: true
  6.         }
  7.     },
  8.     height: 350,
  9.     width: 400,
  10.     stateEvents: [‘saveSelectedItem’],
  11.     stateId:’myTreeId’,
  12.     stateful:true,
  13.     rootVisible: false,
  14.     mySelectedItem:”,//my own added Variable
  15.     getState : function () {
  16.         /*this is place where we state what things are to be saved*/
  17.         console.log(‘saving’+this.mySelectedItem);
  18.         /*we return thing to be save in format key:value*/
  19.         return {
  20.             mySelectedItem: this.mySelectedItem
  21.         }
  22.     },
  23.     applyState : function (state) {
  24.         /*this is place where we recover the saved state*/
  25.         console.log(state);
  26.         console.log(“Previosuly selected “+state.mySelectedItem);
  27.      },
  28.     listeners:{
  29.        itemclick:{fn:function (view, record, item, index, even) {
  30.             console.log(“saving item:”+record.data.text);
  31.             this.mySelectedItem =  record.data.text;
  32.             this.fireEvent(‘saveSelectedItem’);
  33.        }}
  34.     }
  35. });
…………

Nepali – english date converter

Top Clicks

  • None

Blog Stats

  • 13,060 hits