Search code examples
extjsextjs4

Prevent extjs4's treegrid load data at the initialization


I'm using the EXTJS4's tree grid (Ext.tree.panel).

I have create a model and treestore to load the tree data, and specified the store to the treegrid, the code is the following:

var complist = Ext.create('Ext.data.TreeStore', {
    model: PFSComponent,
    proxy: {
        type: 'ajax',
        url: 'getpfscomponents.php',
        reader: {
            type: 'json'
        }
    }
});

var compPanel = Ext.create('Ext.tree.Panel', {
    title: 'lowdisks',
    height: 300,
    collapsible: false,
    useArrows: false,
    rootVisible: false,
    multiSelect: false,
    singleExpand: false,
    region: 'south',
    store: complist,
    columns: [{
        xtype: 'treecolumn', //this is so we know which column will show the tree
        text: 'name',
        flex: 2,
        sortable: false,
        dataIndex: 'name'
    }, {
        text: 'type',
        dataIndex: 'type',
        flex: 1,
        sortable: false
    }, {
        text: 'device',
        dataIndex: 'devicename',
        flex: 1,
        sortable: false
    }, {
        text: 'mount',
        dataIndex: 'mount',
        flex: 1,
        sortable: false
    }]
});

When the page load, the treegrid will load the data auto, it works very good!

But now I want to do something such as check the db, before the grid loaded.

So I need implement the functions like the following :

  1. check whether the data is satisfied with the request
  2. if it's , the treegrid load the data
  3. or, alert the user

So my question is how to prevent the treegrid to load the data when initialization?

Thank you very much!


Solution

  • Use the beforeload event on your tree loader.. return false from the beforeload event if you want to cancel the tree loading. You can write the code for checking the DB here.