[CLOSED] Manual filter sample

  1. #1

    [CLOSED] Manual filter sample

    Hi,

    I have added manual paging and sorting concept using IQuerable concept. I dont know how to add manual filter option. please help on this manual filter concept.


    can you provide sample code for manual filter option?


    <%@ Page Language="C#" %>
     
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="System.Diagnostics" %>
    <%@ Import Namespace="DAL" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        Host objHost = new Host();
        protected void Store_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            using (var db = new ClientDataContext())
            {
                IQueryable<uspOverAllFundTransactionSeekResult> data = db.uspOverAllFundTransactionSeek(0, "", "", "", null, null, string.Empty).AsQueryable();
                e.Total = data.Count();
                data = db.uspOverAllFundTransactionSeek(0, "", "", "", null, null, string.Empty).Skip(e.Start).Take(e.Limit).AsQueryable();
     
                string s = e.Parameters[GridFilters1.ParamPrefix];
             
              // need to add manual filter code
     
                if (!string.IsNullOrEmpty(e.Sort))
                {
                    data = ExtensionMethods.SortBy(data, e.Sort, e.Dir.ToString().ToUpper());
                }
                List<uspOverAllFundTransactionSeekResult> rangeData = data.ToList();
                var limit = e.Limit;
                if ((e.Start + e.Limit) > rangeData.Count())
                {
                    limit = rangeData.Count() - e.Start;
                }
                this.GridPanel1.GetStore().DataSource = rangeData;
            }
     
        }
     
        protected void RefineSearch_Click(object sender, DirectEventArgs e)
        {
            //Store1.reload();
            // how to set  store total record count  e.Total = data.Count();
        }
         
    </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>INTL Example</title>
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store ID="Store1" RemoteSort="true" RemoteGroup="true" runat="server" OnRefreshData="Store_RefreshData">
                    <Proxy>
                        <ext:PageProxy />
                    </Proxy>
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="FXID" Type="Int" />
                                <ext:RecordField Name="BuyCurrency" Type="String" />
                                <ext:RecordField Name="BuyAmount" Type="Float" />
                                <ext:RecordField Name="SellCurrency" Type="String" />
                                <ext:RecordField Name="SellAmount" Type="Float" />
                                <ext:RecordField Name="Requester" Type="String" />
                                <ext:RecordField Name="ReqValueDate" Type="Date" />
                                <ext:RecordField Name="DeliveryName" Type="String" />
                                <ext:RecordField Name="RateEntered" Type="Float" />
                                <ext:RecordField Name="CreatedDate" Type="Date" />
                                <ext:RecordField Name="CancelStatus" Type="Int" />
                                <ext:RecordField Name="FocusTraderID" Type="String" />
                                <ext:RecordField Name="CompanyName" Type="String" />
                                <ext:RecordField Name="FocusID" Type="Int" />
                                <ext:RecordField Name="IsAttachedFile" Type="Int" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                    <BaseParams>
                        <ext:Parameter Name="start" Value="0" Mode="Raw" />
                        <ext:Parameter Name="limit" Value="10" Mode="Raw" />
                    </BaseParams>
                </ext:Store>
            </Store>
            <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column Header="Company" DataIndex="CompanyName" Align="Left" Sortable="true">
                    </ext:Column>
                    <ext:Column Header="FXID" DataIndex="FXID" Sortable="true" Align="Left">
                    </ext:Column>
                    <ext:Column Header="Attachement Dtl" DataIndex="FXID" MenuDisabled="true">
                    </ext:Column>
                    <ext:Column Header="Delivery Name" DataIndex="DeliveryName" Align="Left" Sortable="true">
                    </ext:Column>
                    <ext:Column Header="Sell Currency" ColumnID="BuyCurrency" DataIndex="BuyCurrency"
                        Align="Left" Sortable="true">
                    </ext:Column>
                    <ext:NumberColumn Header="Sell Amount" Format="0,000.00" DataIndex="BuyAmount" Sortable="true"
                        Align="Right">
                    </ext:NumberColumn>
                    <ext:Column Header="Buy Currency" DataIndex="SellCurrency" Align="Left" Sortable="true">
                    </ext:Column>
                    <ext:NumberColumn Header="Buy Amount" Format="0,000.00" DataIndex="SellAmount" Sortable="true"
                        Align="Right">
                    </ext:NumberColumn>
                    <ext:Column Header="Rate" DataIndex="RateEntered" Sortable="true" Align="Right">
                    </ext:Column>
                    <ext:Column Header="Requester" DataIndex="Requester" Align="Left" Sortable="true">
                    </ext:Column>
                    <ext:DateColumn Header="Created Date" Format="MMM dd, Y h:m:s A" DataIndex="CreatedDate"
                        Align="Left" Sortable="true">
                    </ext:DateColumn>
                    <ext:DateColumn Header="Req value Date" Format="MMM dd, Y" DataIndex="ReqValueDate"
                        Align="Left" Sortable="true">
                    </ext:DateColumn>
                    <ext:Column Header="INTL Trader ID" DataIndex="FocusTraderID" Align="Left" Sortable="true">
                    </ext:Column>
                    <ext:Column Header="Focus ID" DataIndex="FocusID" Align="Left" Sortable="true">
                    </ext:Column>
                </Columns>
            </ColumnModel>
            <Plugins>
                <ext:GridFilters ID="GridFilters1"  runat="server">
                    <Filters>
                        <ext:StringFilter DataIndex="CompanyName" />
                        <ext:NumericFilter DataIndex="FXID" />
                        <ext:NumericFilter DataIndex="FXID" />
                        <ext:StringFilter DataIndex="DeliveryName" />
                        <ext:StringFilter DataIndex="BuyCurrency" />
                        <ext:NumericFilter DataIndex="BuyAmount" />
                        <ext:StringFilter DataIndex="SellCurrency" />
                        <ext:NumericFilter DataIndex="SellAmount" />
                        <ext:NumericFilter DataIndex="RateEntered" />
                        <ext:StringFilter DataIndex="Requester" />
                        <ext:DateFilter DataIndex="CreatedDate" />
                        <ext:DateFilter DataIndex="ReqValueDate" />
                        <ext:NumericFilter DataIndex="FocusTraderID" />
                        <ext:NumericFilter DataIndex="FocusID" />
                    </Filters>
                </ext:GridFilters>
            </Plugins>
            <BottomBar>
                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" />
            </BottomBar>
        </ext:GridPanel>
        <ext:ImageButton ID="imbSubmitApp" runat="server" SkinID="Submit" CausesValidation="true">
            <DirectEvents>
                <Click OnEvent="RefineSearch_Click">
                </Click>
            </DirectEvents>
        </ext:ImageButton>
        </form>
    </body>
    </html>
    Last edited by Daniil; Jan 24, 2012 at 5:24 AM. Reason: [CLOSED]
  2. #2

    Solved

    hi,

    i got a sample code.

    <%@ Page Language="C#" %>
     
    <%@ Import Namespace="System.Collections.ObjectModel" %>
    <%@ Import Namespace="System.Collections.Generic" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
        {
            List<TraderInfo> data = FiltersTestData.Data;
     
            string s = e.Parameters[this.GridFilters1.ParamPrefix];
            //or with hardcoding - string s = e.Parameters["gridfilters"];;
           
           
            //-- start filtering ------------------------------------------------------------
            if (!string.IsNullOrEmpty(s))
            {
                FilterConditions fc = new FilterConditions(s);
     
                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.Boolean:
                            value = condition.ValueAsBoolean;
                           break;
                        case FilterType.Date:
                            value = condition.ValueAsDate;
                            break;
                        case FilterType.List:
                            value = condition.ValuesList;
                            break;
                        case FilterType.Numeric:
                            if (data.Count > 0 && data[0].GetType().GetProperty(field).PropertyType == typeof(int))
                            {
                                value = condition.ValueAsInt;
                            }
                            else
                            {
                                value = condition.ValueAsDouble;
                            }
                           
                            break;
                        case FilterType.String:
                            value = condition.Value;
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                   
                    data.RemoveAll(
                        item =>
                            {
                                object oValue = item.GetType().GetProperty(field).GetValue(item, null);
                                IComparable cItem = oValue as IComparable;
                               
                                switch (comparison)
                                {
                                    case Comparison.Eq:
                                       
                                        switch(type)
                                        {
                                            case FilterType.List:
                                                return !(value as ReadOnlyCollection<string>).Contains(oValue.ToString());
                                            case FilterType.String:
                                                return !oValue.ToString().StartsWith(value.ToString());
                                            default:
                                                return !cItem.Equals(value);
                                        }
                                       
                                    case Comparison.Gt:
                                        return cItem.CompareTo(value) < 1;
                                    case Comparison.Lt:
                                        return cItem.CompareTo(value) > -1;
                                    default:
                                        throw new ArgumentOutOfRangeException();
                                }
                            }
                    );
                }
            }
          
            var limit = e.Limit;
           
            if ((e.Start + e.Limit) > data.Count)
            {
                limit = data.Count - e.Start;
            }
     
            List<TraderInfo> rangeData = (e.Start < 0 || limit < 0) ? data : data.Skip(e.Start).Take(limit).ToList();
            //-- end paging ------------------------------------------------------------
     
            //The Total can be set in RefreshData event as below
            //or (Store1.Proxy.Proxy as PageProxy).Total in anywhere
            //Please pay attention that the Total make a sence only during DirectEvent because
            //the Store with PageProxy get/refresh data using ajax request
     
            e.Total = data.Count;
           
            this.GridPanel1.GetStore().DataSource = rangeData;
        }
     
        public class TraderInfo
        {
            private  int _Id;
            private  double _Price;
            private  string _Company;
            private  DateTime _Date;
            private  Boolean _Visible;
            private  string _Size;
     
            public int Id
            {
                set { _Id = value; }
                get { return _Id; }
            }
     
            public double Price
            {
                get { return _Price; }
                set { _Price = value; }
            }
     
            public string Company
            {
                get { return _Company; }
                set { _Company = value; }
            }
     
            public DateTime Date
            {
                get { return _Date; }
                set { _Date = value; }
            }
     
            public Boolean Visible
            {
                get { return _Visible; }
                set { _Visible = value; }
            }
     
            public string Size
            {
                get { return _Size; }
                set { _Size = value; }
            }
        }
       
        public static class FiltersTestData
        {
            public static List<TraderInfo> Data
            {
                get
                {
                    List<TraderInfo> goods = new List<TraderInfo>
                                {                         
                                    new TraderInfo
                                        {                                         
                                            Id = 1,
                                            Price = 71.72,
                                            Company = "3m Co",
                                            Date = new DateTime(2007, 9, 1),
                                            Size = "large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 2,
                                            Price = 29.01,
                                            Company = "Aloca Inc",
                                            Date = new DateTime(2007, 08, 01),
                                            Size = "medium",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 3,
                                            Price = 83.81,
                                            Company = "Altria Group Inc",
                                            Date = new DateTime(2007, 08, 03),
                                            Size = "large",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 4,
                                            Price = 52.55,
                                            Company = "American Express Company",
                                            Date = new DateTime(2008, 01, 04),
                                            Size = "extra large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 5,
                                            Price = 64.13,
                                            Company = "American International Group Inc.",
                                            Date = new DateTime(2008, 03, 04),
                                            Size = "small",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 6,
                                            Price = 31.61,
                                            Company = "AT&T Inc.",
                                            Date = new DateTime(2008, 02, 01),
                                            Size = "extra large",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 7,
                                            Price = 75.43,
                                            Company = "Boeing Co.",
                                            Date = new DateTime(2008, 01, 01),
                                            Size = "large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 8,
                                            Price = 67.27,
                                            Company = "Caterpillar Inc.",
                                            Date = new DateTime(2007, 12, 03),
                                            Size = "medium",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 9,
                                            Price = 49.37,
                                            Company = "Citigroup, Inc.",
                                            Date = new DateTime(2007, 11, 24),
                                            Size = "large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 10,
                                            Price = 40.48,
                                            Company = "E.I. du Pont de Nemours and Company",
                                            Date = new DateTime(2007, 05, 09),
                                            Size = "extra large",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 11,
                                            Price = 68.1,
                                            Company = "Exxon Mobile Corp",
                                            Date = new DateTime(2007, 12, 12),
                                            Size = "large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 12,
                                            Price = 34.14,
                                            Company = "General Electric Company",
                                            Date = new DateTime(2008, 06, 16),
                                            Size = "extra large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 13,
                                            Price = 30.27,
                                            Company = "General Motors Corporation",
                                            Date = new DateTime(2006, 12, 07),
                                            Size = "medium",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 14,
                                            Price = 36.53,
                                            Company = "Hewlett-Packard Co.",
                                            Date = new DateTime(2007, 05, 13),
                                            Size = "large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 15,
                                            Price = 38.77,
                                            Company = "Honweywell Intl Inc",
                                            Date = new DateTime(2006, 11, 07),
                                            Size = "medium",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 16,
                                            Price = 19.88,
                                            Company = "Intel Corporation",
                                            Date = new DateTime(2007, 01, 09),
                                            Size = "small",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 17,
                                            Price = 81.41,
                                            Company = "International Business Machines",
                                            Date = new DateTime(2005, 01, 21),
                                            Size = "extra large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 18,
                                            Price = 64.72,
                                            Company = "Johnson & Johnson",
                                            Date = new DateTime(2008, 01, 10),
                                            Size = "extra large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 19,
                                            Price = 45.73,
                                            Company = "JP Morgan & Chase & Co",
                                            Date = new DateTime(2008, 02, 20),
                                            Size = "large",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 20,
                                            Price = 36.76,
                                            Company = "McDonald's Corporation",
                                            Date = new DateTime(2007, 06, 12),
                                            Size = "large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 21,
                                            Price = 27.96,
                                            Company = "Pfizer Inc",
                                            Date = new DateTime(2007, 12, 30),
                                            Size = "small",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 22,
                                            Price = 45.07,
                                            Company = "The Coca-Cola Company",
                                            Date = new DateTime(2007, 01, 30),
                                            Size = "medium",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 23,
                                            Price = 34.64,
                                            Company = "The Home Depot, Inc",
                                            Date = new DateTime(2006, 12, 31),
                                            Size = "small",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 24,
                                            Price = 61.91,
                                            Company = "The Procter & Gamble Company",
                                            Date = new DateTime(2007, 04, 08),
                                            Size = "extra large",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 25,
                                            Price = 63.26,
                                            Company = "United Technologies Corporation",
                                            Date = new DateTime(2006, 06, 04),
                                            Size = "medium",
                                            Visible = true
                                        },
                                    new TraderInfo
                                        {
                                            Id = 26,
                                            Price = 35.57,
                                            Company = "Verizon Communications",
                                            Date = new DateTime(2005, 07, 09),
                                            Size = "small",
                                            Visible = false
                                        },
                                    new TraderInfo
                                        {
                                            Id = 27,
                                            Price = 45.45,
                                            Company = "Wal-Mart Stores, Inc",
                                            Date = new DateTime(2006, 09, 09),
                                            Size = "large",
                                            Visible = true
                                        }
                                };
     
                    return goods;
                }
            }
        }
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>GridPanel with Remote Filtering, Sorting and Paging - Ext.NET Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
           
            <h1>GridPanel with Remote Filtering, Sorting and Paging</h1>
           
            <p>Please see column header menu for apllying filters</p>
           
            <ext:Window 
                ID="Window1" 
                runat="server" 
                Width="700" 
                Height="400" 
                Closable="false"
                Collapsible="true" 
                Title="Example"
                Maximizable="true"
                Layout="Fit">
                <Items>
                    <ext:GridPanel ID="GridPanel1" runat="server" Border="false">
                        <Store>
                            <ext:Store runat="server" RemoteSort="true" OnRefreshData="Store1_RefreshData">
                                <Proxy>
                                    <ext:PageProxy />
                                </Proxy>
                                <Reader>
                                    <ext:JsonReader IDProperty="Id">
                                        <Fields>
                                            <ext:RecordField Name="Id" Type="Int" />
                                            <ext:RecordField Name="Company" Type="String" />
                                            <ext:RecordField Name="Price" Type="Float" />
                                            <ext:RecordField Name="Date" Type="Date" DateFormat="yyyy-MM-ddTHH:mm:ss" />
                                            <ext:RecordField Name="Size" Type="String" />
                                            <ext:RecordField Name="Visible" Type="Boolean" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                                <BaseParams>
                                    <ext:Parameter Name="start" Value="0" Mode="Raw" />
                                    <ext:Parameter Name="limit" Value="10" Mode="Raw" />
                                    <ext:Parameter Name="sort" Value="" />
                                    <ext:Parameter Name="dir" Value="" />
                                </BaseParams>
                                <SortInfo Field="Company" Direction="ASC" />
                            </ext:Store>
                        </Store>
                        <ColumnModel runat="server">
                                     <Columns>
                                <ext:Column Header="Id" DataIndex="Id" />
                                <ext:Column Header="Company" DataIndex="Company" />
                                <ext:Column Header="Price" DataIndex="Price">
                                    <Renderer Format="UsMoney" />
                                </ext:Column>                        
                                <ext:DateColumn Header="Date" DataIndex="Date" Align="Center" Format="yyyy-MM-dd" />
                                <ext:Column Header="Size" DataIndex="Size" />
                                <ext:Column Header="Visible" DataIndex="Visible" Align="Center">
                                    <Renderer Handler="return (value) ? 'Yes':'No';" />
                                </ext:Column>
                                     </Columns>
                        </ColumnModel>
                        <LoadMask ShowMask="true" />
                        <Plugins>
                            <ext:GridFilters runat="server" ID="GridFilters1">
                                <Filters>
                                    <ext:NumericFilter DataIndex="Id" />
                                    <ext:StringFilter DataIndex="Company" />
                                    <ext:NumericFilter DataIndex="Price" />
                                    <ext:DateFilter DataIndex="Date">
                                        <DatePickerOptions runat="server" TodayText="Now" />
                                    </ext:DateFilter>
                                    <ext:ListFilter DataIndex="Size" Options="extra small,small,medium,large,extra large" />
                                    <ext:BooleanFilter DataIndex="Visible" />
                                </Filters>
                            </ext:GridFilters>
                        </Plugins>
                        <BottomBar>
                            <ext:PagingToolbar runat="server" PageSize="10" />
                        </BottomBar>
                    </ext:GridPanel>
                </Items>
            </ext:Window>    
        </form>
    </body>
    </html>
  3. #3

    IQueryable RemoveAll Not working

    Hi,

    When i use List The below method is working perfectly.
    data.RemoveAll(
    item =>


    but when i use IQueryable(data) instead of list , RemoveAll method is not working. Is there any other solution for remove all items from IQueryable data.
  4. #4
  5. #5

    Manual filter option

    hi,

    i saw Coolite example how to use grid filters using list object.

    https://examples1.ext.net/#/GridPane...ilters_Remote/

    but i need an example grid filters using iquerable object.


    how i can achieve this?
  6. #6
    Unfortunately, we have no such example with IQueryable

    I think it would be best to look at its API.
    http://msdn.microsoft.com/en-us/libr...queryable.aspx

Similar Threads

  1. [CLOSED] Manual toolbarPaging
    By supera in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 10, 2012, 12:11 PM
  2. GridPanel Store manual filter
    By cwolcott in forum 1.x Help
    Replies: 2
    Last Post: Jan 19, 2012, 4:06 PM
  3. Manual Implementation of Paging
    By Nojj02 in forum 1.x Help
    Replies: 0
    Last Post: Aug 31, 2010, 11:45 PM
  4. [CLOSED] Manual set of SqlDataSource V 1.0
    By egodoy in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 09, 2010, 1:00 PM
  5. manual installation in hosting provider
    By tkm in forum 1.x Help
    Replies: 2
    Last Post: Sep 20, 2009, 6:01 AM

Tags for this Thread

Posting Permissions