-
26 Nov 2012 4:09 AM #1
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
And the store: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' } });
I want to set an emptyText (or just show it) when 'exception' is fired. Is it possible?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 }); } } });
-
28 Nov 2012 12:22 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
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.
-
30 Nov 2012 2:10 AM #3
I add a listener through store proxy events and it works:
But the emptyText doesn't appear. Why?Code:this.store.proxy.on('exception', function (proxy, response, operation) { me.emptyText = 'Error: ' + response.statusText + '<br/>Code: ' + response.status; me.view.loadMask.hide(); });
-
30 Nov 2012 10:35 PM #4
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.
I need one little step to update emptyText from default to custom.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(); });
-
30 Nov 2012 11:14 PM #5
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(); });


Reply With Quote