1. #1
    Sencha User coshmos's Avatar
    Join Date
    Apr 2012
    Posts
    17
    Vote Rating
    0
    coshmos is on a distinguished road

      0  

    Default Set an empty text to grid if store has an exception

    Set an empty text to grid if store has an exception


    Hi.

    I've got the panel
    Code:
    Ext.create('Ext.grid.Panel', {
        title: 'Simpsons',
        store: Ext.data.StoreManager.lookup('simpsonsStore'),
        columns: [{
            text: 'Name',
            dataIndex: 'name'
        },
        {
            text: 'Email',
            dataIndex: 'email',
            flex: 1
        },
        {
            text: 'Phone',
            dataIndex: 'phone'
        }],
        height: 200,
        width: 400,
        renderTo: Ext.getBody(),
        viewConfig: {
            emptyText: 'Something is wrong'
        }
    });
    And the store:
    Code:
    Ext.create('Ext.data.Store', {
        storeId: 'simpsonsStore',
        fields: ['name', 'email', 'phone'],
        data: {
            'items': [{
                'name': 'Lisa',
                "email": "lisa@simpsons.com",
                "phone": "555-111-1224"
            },
            {
                'name': 'Bart',
                "email": "bart@simpsons.com",
                "phone": "555-222-1234"
            },
            {
                'name': 'Homer',
                "email": "home@simpsons.com",
                "phone": "555-222-1244"
            },
            {
                'name': 'Marge',
                "email": "marge@simpsons.com",
                "phone": "555-222-1254"
            }]
        },
        proxy: {
            type: 'memory',
            reader: {
                type: 'json',
                root: 'items'
            }
        },
        url: 'StoreUrl',
        listeners: {
            exception: function(proxy, response, operation) {
                Ext.Msg.show({
                    title: 'Exception',
                    msg: response.statusText + response.status,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                });
            }
        }
    });
    I want to set an emptyText (or just show it) when 'exception' is fired. Is it possible?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,599
    Vote Rating
    434
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    The view will listen to the load event of the store and if the store has zero records in it it will show the emptyText. It may listen to datachanged, not 100% on that without looking.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User coshmos's Avatar
    Join Date
    Apr 2012
    Posts
    17
    Vote Rating
    0
    coshmos is on a distinguished road

      0  

    Default


    I add a listener through store proxy events and it works:
    Code:
    this.store.proxy.on('exception', function (proxy, response, operation) {
    	me.emptyText = 'Error: ' + response.statusText + '<br/>Code: ' + response.status;
    	me.view.loadMask.hide();
    });​
    But the emptyText doesn't appear. Why?

  4. #4
    Sencha User coshmos's Avatar
    Join Date
    Apr 2012
    Posts
    17
    Vote Rating
    0
    coshmos is on a distinguished road

      0  

    Default


    Ok. The EmptyText doesn't appear because I've got dirty data. So, I just add a dummy row and then remove all rows. Not a good code, but it's working.
    Code:
    this.store.proxy.on('exception', function (proxy, response, operation) {
                if (autoUpdateTask)
                    Ext.TaskManager.stop(autoUpdateTask);
                me.emptyText = 'Error: ' + response.statusText + '<br/>Code: ' + response.status;
                if (me.items.items[0]) {
                    me.items.items[0].store.add({});
                    me.items.items[0].store.removeAll();
                }
                me.view.loadMask.hide();
    });
    I need one little step to update emptyText from default to custom.

  5. #5
    Sencha User coshmos's Avatar
    Join Date
    Apr 2012
    Posts
    17
    Vote Rating
    0
    coshmos is on a distinguished road

      0  

    Default


    Done!
    Code:
    		this.store.proxy.on('exception', function (proxy, response, operation) {
    			if (autoUpdateTask)
    				Ext.TaskManager.stop(autoUpdateTask);
    			var emptyText = 'Error: ' + response.statusText + '<br/>Code: ' + response.status;
    			me.view.emptyText = '<div class="x-grid-empty">' + emptyText + '</div>';
    			if (me.items.items[0]) {
    				me.items.items[0].store.add({});
    				me.items.items[0].store.removeAll();
    			}
    			me.view.loadMask.hide();
    		});