tags:

views:

359

answers:

2

Hi

I would like to persist filters applied on gridpanel on page refresh. Can you please guide me in doing this.

Thanks.

A: 

Turn on the Ext JS state manager globally (where you set Ext.BLANK_IMAGE_URL).

Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

User changes to some components will now be stored in a cookie, which will persist across requests. If you need to store additional custom data, you can do that using Ext.state.Manager.set and Ext.state.Manager.get. State is configurable on individual components.

Saki has a good example.

Jonathan Julian
Ext state manger is turned on .the problem is grid panel shows that filters is checked and the data inside it (textbox) is also persisted but the problem is i dont see the filtered grid when i clcik refresh. Can you please help me on this.
xrx215
You might need to manually reload the store when the state is restored. Post some code so we can reproduce it.
Jonathan Julian
can you please see the posted code and help me from there.
xrx215
Hi..The value of the filter textbox is stored in cookie(read cookie in ext-all-debug.js).But when page reloads getfilterdata and buildquery in beforeload are not being called. The beforeload function of gridfilters.js is not being called when page is refreshed.can you please help me on this.
xrx215
A: 

Here is the code which send the filter data to webservice

Ext.extend(Ext.ux.AspWebServiceProxy, Ext.data.DataProxy,

{

load: function(params, reader, callback, scope, arg) {

var userContext = { callback: callback,

reader: reader, arg: arg, scope: scope };

           var proxyWrapper = this;

           //debugger;
           //Handles the response we get back from the web service call
           var webServiceCallback = function(response, context, methodName) {
               proxyWrapper.loadResponse(response, userContext, methodName);
           }

           var serviceParams = [];
           var filters = {};
           //Convert the params into an array of values so that they can be used in the call (note assumes that the properties on the object are in the correct order)
           for (var property in params) {
               if (property.indexOf("filter[") == 0) {
                   filters[property] = params[property];
               }
               else {
                   serviceParams.push(params[property]);
               }
               //console.log("Property: ", property, "Value: ", params[property]);
           }
           serviceParams.push(filters);

           //Add the webservice callback handlers
           serviceParams.push(webServiceCallback);
           serviceParams.push(this.handleErrorResponse);

           //Make the actual ASP.Net web service call
           this.webServiceProxyMethod.apply(this.webServiceProxy, serviceParams);
       },

       handleErrorResponse: function(response, userContext, methodName) {
           window.location.reload();
           //                               Ext.MessageBox.show({
           //                                       title: 'Error',
           //                                       msg: response.get_message(),
           //                                       buttons: Ext.MessageBox.OK,
           //                                       icon: Ext.MessageBox.ERROR
           //                                   });
           //alert("Error while calling method: " + methodName + "n" + response.get_message());
       },

       loadResponse: function(response, userContext, methodName) {
           var result = userContext.reader.readRecords(response);
           userContext.callback.call(userContext.scope, result, userContext.arg, true);
       }

   });
xrx215