在Ext.Net网格面板中过滤问题

时间:2016-05-10 09:52:21

标签: ext.net

在Ext.Net中使用ext:GridFilters

下的Filters项目

我在ext:GridFilters下不支持过滤器。请建议如何解决此问题

2 个答案:

答案 0 :(得分:0)

Aspx Page

<%@ 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 Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            this.Store1.DataSource = FiltersTestData.Data;
            this.Store1.DataBind();
        }
    }

    protected void SetFilter(object sender, DirectEventArgs e)
    {
        StringFilter sf = (StringFilter)GridFilters1.Filters[1];
        sf.SetValue("xyz");
        sf.SetActive(true);
    }
</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 Local Filtering, Sorting and Paging - Ext.NET Examples</title>
    <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <ext:ResourceManager runat="server" DirectEventUrl="default.aspx" />

    <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">
        <Reader>
            <ext:JsonReader IDProperty="StudentNo">
                <Fields>
                    <ext:RecordField Name="StudentNo" Type="Int" />
                    <ext:RecordField Name="StudentName" Type="String" />
                    <ext:RecordField Name="StudentSurname" Type="String" />                   
                </Fields>
            </ext:JsonReader>
        </Reader>
        <SortInfo Field="StudentSurname" Direction="ASC" />
    </ext:Store>

    <ext:Window 
        ID="Window1" 
        runat="server"         
        Width="700" 
        Height="400" 
        Closable="false"
        Collapsible="true"
        Title="Example" 
        Maximizable="true"
        Layout="Fit">
        <Items>
            <ext:GridPanel runat="server" ID="GridPanel1" Border="false" StoreID="Store1">
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column Header="StudentNo" DataIndex="StudentNo" />
                        <ext:Column Header="StudentName" DataIndex="StudentName" />                                               
                        <ext:Column Header="StudentSurname" DataIndex="StudentSurname" />                      
                    </Columns>
                </ColumnModel>
                <LoadMask ShowMask="true" />
                <Plugins>
                    <ext:GridFilters runat="server" ID="GridFilters1" Local="true">
                        <Filters>
                            <ext:NumericFilter DataIndex="StudentNo" />
                            <ext:StringFilter DataIndex="StudentName" />
                            <ext:StringFilter DataIndex="StudentSurname" />                         
                        </Filters>
                    </ext:GridFilters>
                </Plugins>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="10">
                        <Items>
                            <ext:ToolbarSeparator runat="server" />
                            <ext:Button runat="server" Text="Find 'xyz'">
                                <DirectEvents>
                                    <Click OnEvent="SetFilter" />
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:PagingToolbar>
                </BottomBar>                   
            </ext:GridPanel>
        </Items>
    </ext:Window>
</body>
</html>

cs页面:

using System;
using System.Collections.Generic;

public class FiltersTestData
{
    public static List<object> Data
    {
        get
        {
            var StudentInfo = new List<object>
                            {
                                new
                                    {
                                        StudentNo = 1,
                                        StudentName = "xy",
                                        StudentSurname = "xyz"
                                    },
                                new
                                    {
                                        StudentNo = 2,
                                        StudentName = "AB",
                                        StudentSurname = "ABC"
                                    },
                                new
                                    {
                                       StudentNo = 3,
                                        StudentName = "pq",
                                        StudentSurname = "pqr"
                                   }
                            };

            return StudentInfo;
        }
    }
}

请尝试此代码。

答案 1 :(得分:0)

这个解决方案适合我:

<ext:GridPanel ID="GridPanelDatiAssociati" runat="server" Title="Dati associati" Stateful="true">    
<Store>                          
    <ext:Store ID="StoreDatiAssociati" runat="server" PageSize="6">
        <Model>
            <ext:Model ID="ModelDatiAssociati" runat="server" IDProperty="ID">
                <Fields>
                    <ext:ModelField Name="ID" />
                    <ext:ModelField Name="PARAMETRO" />
                    <ext:ModelField Name="DESCRIZIONE" />                                                    
                    <ext:ModelField Name="UNITA" />
                    <ext:ModelField Name="VALORE" />                                           
                  </Fields>
            </ext:Model>
        </Model>
    </ext:Store>
</Store>
<ColumnModel ID="ColumnModelDatiAssociati" runat="server">
    <Columns>
            <ext:Column ID="ColumnID_DATI_ASSOCIATI" runat="server" Text="ID" DataIndex="ID" Width="100" Hidden = "true" >                                        
            </ext:Column>

            <ext:Column ID="ColumnPARAMETRO" runat="server" Width="100" Text="Parametro" DataIndex="PARAMETRO">                                        
                <Filter>
                    <ext:StringFilter />
                </Filter>
            </ext:Column>

            <ext:Column ID="ColumnUNITA" runat="server" Width="170" Text="Unità" DataIndex="UNITA">
                <Filter>
                    <ext:DateFilter>
                        <DatePickerOptions runat="server" TodayText="Now" />
                    </ext:DateFilter>
                </Filter>
            </ext:Column>

            <ext:Column ID="ColumnVALORE" runat="server" Width="170" Text="Valore" DataIndex="VALORE">
                <Filter>
                    <ext:DateFilter>
                        <DatePickerOptions runat="server" TodayText="Now" />
                    </ext:DateFilter>
                </Filter>
            </ext:Column>                                   
    </Columns> 
</ColumnModel>  

<Plugins>
    <ext:GridFilters ID="GridFiltersDatiAssociati" runat="server">
    </ext:GridFilters>
</Plugins>

</ext:GridPanel>