Get filter string for Remote Filtering

  1. #1

    Get filter string for Remote Filtering

    I currently have this code for remote paging/sorting, I also want the server to return remotely fitlered datasets:

    <ext:Store runat="server" ID="storeGridData" RemotePaging="true" RemoteSort="true"
            RemoteGroup="true" IgnoreExtraFields="true" AutoLoad="false">
            <BaseParams>
                <ext:Parameter Name="filter" Value="" Mode="Value" />
                <ext:Parameter Name="start" Value="={0}" />
                <ext:Parameter Name="limit" Value="={10}" />
                <ext:Parameter Mode="Raw" Name="cdRef" Value="#{txtCdRef}.getValue()" />
                <ext:Parameter Mode="Raw" Name="cdDate" Value="#{dateCdDate}.getValue()" />
            </BaseParams>
            <Proxy>
                <ext:HttpProxy Url="/Commission/GetSearchResults/" Method="POST" />
            </Proxy>
            <Reader>
                <ext:JsonReader Root="data" TotalProperty="total">
                    <Fields>
                        <ext:RecordField Name="Id" />
                        <ext:RecordField Name="AutogenerateRef" />
                        <ext:RecordField Name="BankedAmount" />
                        <ext:RecordField Name="BankedDate" />
                        <ext:RecordField Name="BankRef" />
                        <ext:RecordField Name="CreatedByUserId" />
                        <ext:RecordField Name="DebitBalance" />
                        <ext:RecordField Name="Description" />
                        <ext:RecordField Name="MonthRef" />
                        <ext:RecordField Name="PaymentMethodId" />
                        <ext:RecordField Name="ReconciledByUserId" />
                        <ext:RecordField Name="ReconciledDate" />
                        <ext:RecordField Name="ReconciledStatus" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="Id" Direction="ASC" />
        </ext:Store>
    The part where I'm setting the BaseParams for the filter string.. I have no idea what to put in there; in a previous example I saw

    #{gridSearchResults}.GridFilters()
    being used, but this doesnt work. How do I get the current filter (string, is it?) to pass to my controller action?
  2. #2

    a code sample

    You are speaking about a mvc app, i guess.

    Just have a look and I am sure that you will get it.

    Controller:
     public AjaxStoreResult GetSites(int limit, int start, string dir, string sort, string gridfilters)
            {
             
               var sites =  (from s in this.DBContext.Sites
                            select new {
                                s.SiteID,
                                s.SiteCode,
                                s.City,
                                s.SiteClass,                                          
                            } );
    
          if (!string.IsNullOrEmpty(gridfilters))
               {
                   FilterConditions fc = new FilterConditions(gridfilters);
    
                   foreach (FilterCondition condition in fc.Conditions)
                   {
                       Comparison comparison = condition.Comparison;
                       string field = condition.Name;
                       FilterType type = condition.FilterType;
    
                       object value;
    
                       switch (condition.FilterType)
                       {
                           case FilterType.Date:
                                    switch(comparison)
                                    {
                                        case Comparison.Eq:
                                            sites = from c in sites where c.OnAirDate == DateTime.Parse(condition.Value, new System.Globalization.CultureInfo("en-US")) select c;
                                            break;
                                        case Comparison.Gt:
                                            sites = from c in sites where c.OnAirDate > DateTime.Parse(condition.Value, new System.Globalization.CultureInfo("en-US")) select c;
                                            break;
                                        case Comparison.Lt:
                                            sites = from c in sites where c.OnAirDate < DateTime.Parse(condition.Value, new System.Globalization.CultureInfo("en-US")) select c;
                                            break;                                   
                                    }
                               break;
    
                           case FilterType.String:
                               value = condition.Value;
                               value = value.ToString().Replace("'","''");
                               sites = sites.Where(string.Format("{0}.Contains(\"{1}\")",field,value));
                               break;
    
                           default:
                               throw new ArgumentOutOfRangeException();
                       }
    
                   }
               }
    
               int total = sites.ToList().Count;      
               
                return new AjaxStoreResult(sites,total);
            }
    View:
    Insert it inside a Gridpanel, change DataIndex's as you need
      
       <Plugins>
                            <ext:GridFilters runat="server" ID="GridFilters1">
                                <Filters>                              
                                    <ext:StringFilter DataIndex="SiteCode" />
                                    <ext:StringFilter DataIndex="City" />
                                    <ext:NumericFilter DataIndex="Price" />
                                    <ext:DateFilter DataIndex="OnAirDate" Format="yyyy-MM-dd">
                                        <DatePickerOptions runat="server" TodayText="Now" />
                                    </ext:DateFilter>                          
                                </Filters>
                            </ext:GridFilters>
                        </Plugins>
  3. #3
    Thank you. I had stumbled upon something like this as well and was looking to adapt it, thanks.

Similar Threads

  1. Replies: 6
    Last Post: Nov 03, 2012, 11:48 PM
  2. Replies: 1
    Last Post: Nov 01, 2011, 4:10 PM
  3. [1.0] Codebehind and GridFilters/Remote filtering
    By plykkegaard in forum 1.x Help
    Replies: 7
    Last Post: Oct 26, 2011, 11:01 AM
  4. [CLOSED] Remote filtering is not working with proxy
    By Aparna_B in forum 1.x Premium Help
    Replies: 1
    Last Post: Sep 23, 2011, 11:49 AM
  5. remote and local filtering
    By marcmvc in forum 1.x Help
    Replies: 0
    Last Post: Oct 13, 2009, 1:38 PM

Tags for this Thread

Posting Permissions