Results 1 to 6 of 6

Thread: Set an empty text to grid if store has an exception

  1. #1
    Sencha User coshmos's Avatar
    Join Date
    Apr 2012
    Posts
    19
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Vote Rating
    1297
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

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

  3. #3
    Sencha User coshmos's Avatar
    Join Date
    Apr 2012
    Posts
    19
    Vote Rating
    1
      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
    19
    Vote Rating
    1
      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
    19
    Vote Rating
    1
      1  

    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();
    		});

  6. #6
    Sencha User
    Join Date
    Mar 2012
    Location
    California
    Posts
    16
    Vote Rating
    1
      0  

    Default Here is the actual solution

    Grid view is not ready at the time we apply text with me.getView().refresh() so that's reason following works as the private method me.getView().applyFirstRefresh() internally having defer for view to get ready.
    Please try this....

    me.getView().emptyText = 'Test Comment';
    me.getView().applyFirstRefresh();

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •