在网格面板中保持过滤器

时间:2010-02-10 15:43:26

标签: extjs

我想在页面刷新时保留在gridpanel上应用的过滤器。你可以指导我做这件事。

感谢。


以下是将过滤数据发送到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);
       }

   });

2 个答案:

答案 0 :(得分:1)

全局启用Ext JS状态管理器(您设置Ext.BLANK_IMAGE_URL)。

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

现在,用户对某些组件的更改将存储在cookie中,该cookie将在请求中保留。如果您需要存储其他自定义数据,可以使用Ext.state.Manager.setExt.state.Manager.get执行此操作。 State可以在各个组件上进行配置。

Saki有good example

答案 1 :(得分:1)

要在网格上保留过滤器,您可以使用Cookie,在这里您可以找到一些帮助:

proxy: new Ext.data.HttpProxy({
        url: (local ? url.local : url.remote),
        method: 'GET',
        listeners:{
            beforeload : function(dataproxy,param) {
                if(param.searchConditions != undefined && param.searchConditions != '[]') {                     
                    Ext.util.Cookies.set('SearchConditions',param.searchConditions);
                }

            }
        }
    })

在上面的示例中,您可以发现我们正在设置" searchConditions" Cookie中的JSONArray。现在让我们看看如何找回" searchCondition"每当你加载网格时。

store.load({
            params:{
                start:0,
                limit: 50,
                searchConditions:JSON.parse(Ext.util.Cookies.get('SearchConditions'));
            }
        });

这里只需要传递你的" searchCondition"参数值作为存储在Cookie中的值。希望上面的例子很有用。请评论任何帮助。