Grid filters in code-behind

  1. #1

    Grid filters in code-behind



    I want to set gridfilters in codebehind (Page load), is this possible?



  2. #2

    RE: Grid filters in code-behind

    Hi,

    yes, sure, it is possible.
    What kind of problems do you have with GridFilters in code-behind?


  3. #3

    RE: Grid filters in code-behind

    I just don't know how to do it, and I can't find any examples :-)
  4. #4

    RE: Grid filters in code-behind

    Hi petlun,

    Please see the following code
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.ObjectModel" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!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></title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                GridFilters filters = new GridFilters();
                filters.Local = true;
                GridPanel1.Plugins.Add(filters);
                
                NumericFilter nf = new NumericFilter();
                nf.DataIndex = "Id";
                filters.Filters.Add(nf);
    
                StringFilter sf = new StringFilter();
                sf.DataIndex = "Company";
                filters.Filters.Add(sf);
    
                NumericFilter nf1 = new NumericFilter();
                nf1.DataIndex = "Price";
                filters.Filters.Add(nf1);
    
                DateFilter df = new DateFilter();
                df.DataIndex = "Date";
                df.DatePickerOptions.TodayText = "Now";
                filters.Filters.Add(df);
                
                ListFilter lf = new ListFilter();
                lf.DataIndex = "Size";
                lf.Options = "extra small,small,medium,large,extra large".Split(',');
                filters.Filters.Add(lf);
    
                BooleanFilter bf = new BooleanFilter();
                bf.DataIndex = "Visible";
                filters.Filters.Add(bf);
                
                this.Store1.DataSource = FiltersTestData.Data;
                this.Store1.DataBind();
            }
        </script>
    
    </head>
    <body>
        <ext:ScriptManager ID="ScriptManager1" runat="server" StateProvider="None" />
        
        <h1>GridPanel with Local Filtering, Sorting and Paging</h1>
        <p>Please see column header menu for apllying filters</p>
        
        <ext:Store runat="server" ID="Store1" AutoLoad="true" RemoteSort="true">
            <Reader>
                <ext:JsonReader ReaderID="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="Y-m-dTh:i:s" />
                        <ext:RecordField Name="Size" Type="String" />
                        <ext:RecordField Name="Visible" Type="Boolean" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="Company" Direction="ASC" />
        </ext:Store>
        
        <ext:Window 
            ID="Window1" 
            runat="server" 
            Width="700" 
            Height="400" 
            Closable="false"
            Collapsible="true"
            Title="Example" 
            Maximizable="true">
            <Body>
                <ext:FitLayout ID="FitLayout1" runat="server">
                    <ext:GridPanel runat="server" ID="GridPanel1" Border="false" StoreID="Store1">
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:Column Header="Id" DataIndex="Id" Sortable="true" />
                                <ext:Column Header="Company" DataIndex="Company" Sortable="true" />
                                <ext:Column Header="Price" DataIndex="Price" Sortable="true">
                                    <Renderer Format="UsMoney" />
                                </ext:Column>
                                <ext:Column Header="Date" DataIndex="Date" Sortable="true" Align="Center">
                                    <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d')" />
                                </ext:Column>
                                <ext:Column Header="Size" DataIndex="Size" Sortable="true" />
                                <ext:Column Header="Visible" DataIndex="Visible" Sortable="true" Align="Center">
                                    <Renderer Handler="return (value) ? 'Yes':'No';" />
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <LoadMask ShowMask="true" />
                        <BottomBar>
                            <ext:PagingToolBar ID="PagingToolBar1" runat="server" PageSize="10"  />
                        </BottomBar>  
                    </ext:GridPanel>
                </ext:FitLayout>
            </Body>
        </ext:Window>
    </body>
    </html>

  5. #5

    RE: Grid filters in code-behind

    Thanks vladimir for your answer.

    But I want to know how to set the actual filter values. What I'm trying to achieve save the filter for the grid/page and reload them on next visit.

    Best regards
    Peter

Similar Threads

  1. [Razor] Example for grid filters
    By Natalie in forum 2.x Help
    Replies: 4
    Last Post: Apr 23, 2012, 9:22 AM
  2. Replies: 3
    Last Post: Jan 12, 2012, 3:26 PM
  3. [CLOSED] Hidden Change and Grid Filters are not working after Grid Reconfigure
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 15
    Last Post: Oct 16, 2011, 1:12 PM
  4. [CLOSED] Grid Filters Dynamic
    By majunior in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 18, 2011, 3:49 PM
  5. Replies: 16
    Last Post: Feb 23, 2011, 10:03 AM

Posting Permissions