View Full Version : Extjs 4 - instantiate a plugin

22 Oct 2013, 9:03 AM
I have created a tree in ExtJS 4 and now I am trying to add the ability to save the state of the tree.

For saving the state I am trying to use the code in https://github.com/AlexTiTanium/ExtJsStatefulTree and integrate it with my code.

My tree code looks something like this

Ext.define("my.widget.tree.my", {
extend: "Ext.tree.Panel",
alias: "widget.my_mytree",
plugins: ["my_tree_itemeventplugin","treestateful"],
statics: {
getSelectedNodeId : function(context, compId) {
constructor: function(config) {

To this I need to add the treestateful plugin. So I have added the below

Ext.define('Ext.ux.TreeStateful', {
init:function (view) {
var me = this;
view.addStateEvents('afteritemcollapse', 'afteritemexpand');
view['getState'] = me.getState;
view['saveState'] = me.saveState;

if (view.getTreeStore().isLoading()) {
view.getTreeStore().on("load", me.applyState, view);
} else {
Ext.callback(me.applyState, view);

This plugin does get instantiated but it gives me the error -

Uncaught TypeError: Object [object Object] has no method 'getTreeStore'

I suspect that even though the plugin is getting instantiated, an empty 'view' object is getting passed, as a result 'view.getTreeStore()' throws an error.

Can someone please let me know how to instantiate the plugin with the correct 'view' object, so that it allows me to get the tree store using the view object.

Thank you

23 Oct 2013, 9:23 PM
Instead of getTreeStore(), I used the method getStore(). Now I don't get the error I posted above. also, I noticed that the Cookie is being written.

However, I feel the store that is returned does not have anything in it (because of the below error). The below code in the plugin is getting called

applyState:function () { console.log('inside applystate');
var me = this,
id = me.stateful && me.getStateId(),

store = me.getStore(),
if (id) {
state = Ext.state.Manager.get(id);
if (state) {
state = Ext.apply([], state);

Ext.each(state, function (id) {
node = store.getNodeById(id);
if (node) {
node.bubble(function (node) {

and it throws the below error

Uncaught TypeError: cannot read property '0b015abd8000c903' of undefined

Would really appreciate any pointers. Thank you.