PDA

View Full Version : Grid alternate message



ken_opp
31 Mar 2011, 11:08 AM
How can I show a message such as "Too many results, please narrow your results" in the grid when the data store behind my grid returns too many results? Idealy I'd like a back-end service to send back a message, or a success: fail data result with the message to be placed on the grid.

Screamy
31 Mar 2011, 11:35 AM
If you return 'success: false' in the grid's JSON response, you'll trigger an 'exception' event on the store. You can also send back some custom properties like 'msg' and 'title', for use with an Ext.Msg.alert(title, msg);

This assumes that your store uses the 'root' attribute to identify the JSON attribute which houses the grid data.

ken_opp
31 Mar 2011, 2:25 PM
I looked all over and I can't figure out how to get the msg from the JsonStore.

var storeTicketList = new Ext.data.JsonStore({
url: 'TicketView.ashx?type=TICKETLIST',
root: 'root',
totalProperty: 'totalCount',
idProperty: 'TicketId',
messageProperty: 'msg',
...
storeTicketList.on('exception', requestFailed);

function requestFailed(store, type, action, options, response, arg) {
Ext.MessageBox.alert(store.jsonData.msg);

store.jsonData doesn't work. The data coming back looks like:

"{\"success\":false,\"msg\":\"Please search on criteria in addtion to the Order-less field\"}"

Screamy
31 Mar 2011, 3:27 PM
IIRC, you'll have to get at the response via the 'response' argument to your requestFailed() function.

You'll probably also have to decode the response as JSON:



var json = Ext.decode(response.responseText);
Ext.Msg.alert('No Data!', json.msg);

ken_opp
4 Apr 2011, 1:12 PM
Thanks, that worked perfectly