How can I read the filters

  1. #1

    How can I read the filters

    How can I read the filters

    I want to read the filters of the store.
    Here is my example again. When I search in the HeaderFilter and then click on "FindFilter" button, it shows me a count of 0.

    Why?

    I have to read out all filters that are used.

    Thanks

    Imports Ext.Net
    
    Public Class grid2
    
        Inherits System.Web.UI.Page
    
        Dim aktGrid As New GridPanel
        Dim aktTextBox As New TextField
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim aktResourceManager As New ResourceManager
            With aktResourceManager
                .ID = "rm"
                .Theme = Ext.Net.Theme.Neptune
            End With
    
            With aktGrid
    
                .ID = "mwgrid"
                .Width = 700
                .Height = 350
    
                .SelectionModel.Clear()
                .View.Clear()
                .Plugins.Clear()
                .ColumnModel.Columns.Clear()
                .Features.Clear()
                .Store.Clear()
    
                .EnableLocking = True
    
                Dim _Store As New Store
                _Store.ID = "store1"
    
                Dim _Model As New Model
    
                _Model.IDProperty = "Col1"
    
                For i As Integer = 1 To 10
    
    
                    If i = 1 Then
                        _Model.Fields.Add(New ModelField("Col" & i.ToString, ModelFieldType.Int))
                    Else
                        _Model.Fields.Add(New ModelField("Col" & i.ToString, ModelFieldType.String))
                    End If
    
                Next
    
                _Store.Model.Add(_Model)
    
                _Store.DataSource = Me.Data
    
                .Store.Add(_Store)
    
                With .ColumnModel
    
                    Dim nGridCol As New RowNumbererColumn
                    With nGridCol
                        .ID = "RowNumber"
                    End With
    
                    .Columns.Add(nGridCol)
    
                    For i As Integer = 1 To 10
    
                        Dim _Col As Object
    
                        If i = 1 Then
                            _Col = New NumberColumn
                        Else
                            _Col = New Column
                        End If
    
                        _Col.ID = "Col" & i.ToString
                        _Col.Text = "Col" & i.ToString
                        _Col.DataIndex = "Col" & i.ToString
    
                        If i = 1 Then _Col.Locked = True
    
                        .Columns.Add(_Col)
    
                    Next
    
                End With
    
    
                Dim _RowSelModel As New RowSelectionModel
    
                With _RowSelModel
                    .Mode = SelectionMode.Single
                End With
    
    
                .SelectionModel.Add(_RowSelModel)
    
                .Features.Add(New Grouping)
    
                Dim _View As New GridView
                _View.StripeRows = True
                _View.TrackOver = True
    
                .Plugins.Add(New FilterHeader)
    
                .View.Add(_View)
    
            End With
    
            Dim _button As New Button("FindFilter")
            AddHandler _button.DirectEvents.Click.Event, AddressOf Click
            _button.ID = "findfilter"
    
            With aktTextBox
                .ID = "textbox"
            End With
    
    
            Page.FindControl("form1").Controls.Add(aktResourceManager)
            Page.FindControl("form1").Controls.Add(aktGrid)
            Page.FindControl("form1").Controls.Add(_button)
            Page.FindControl("form1").Controls.Add(aktTextBox)
    
            If Not Ext.Net.ExtNet.IsAjaxRequest Then
    
                aktGrid.Store(0).GroupField = "Col2"
    
            End If
    
        End Sub
    
        Private Sub Click(sender As Object, e As DirectEventArgs)
    
            With aktGrid.Store(0)
    
                aktTextBox.Text = .Filters.Count.ToString
    
            End With
    
        End Sub
    
    
        Private ReadOnly Property Data As Object()
            Get
                Data = New Object() {New Object() {1, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {2, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {3, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {4, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {5, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {6, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {7, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {8, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {9, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {10, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {11, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {12, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {13, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {14, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {15, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {16, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {17, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {18, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {19, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {20, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {21, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {22, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {23, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {24, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {25, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {26, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {27, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {28, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {29, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {30, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {31, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {32, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {33, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                    New Object() {34, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {35, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {36, "0. Feasibility Study", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {37, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {38, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {39, "I. Engineering", "test1<br/>test", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"},
                    New Object() {40, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test", "test1", "test1"},
                   New Object() {41, "II. Procurement", "test1", "test1", "test1", "test1", "test1", "test1<br/>test<br/>test", "test1", "test1"}}
    
            End Get
    
        End Property
    
    End Class
  2. #2
    Hello, Gidi!

    This happens because code behind can only know client-side component state if it is passed along the event. In several situations, Ext.NET handles that for you, but it's not always the case, especially when it's hard to tell what is going to be used from components. For instance, it would be cumbersome to pass back all component states to every button click direct request (DirectEvent in the test case) if all you need is the list (or count) of filters in it. Thus, you'd need to ally extra parameters passing with actual FilterHeader Plugin filters, which -- by the way -- is not necessarily the same as the store filters you are querying.

    Please take a look at this example using the FilterHeaders plugin, which also features getting filters from the plugin: Grid Panel > Filter Header > Overview, in particular the Get Fields Values and Get Filter Values buttons which, respectively, returns values filled in the filter header input fields, and actual filter objects for each column that applies.

    Based in your test case, the easiest way to get the count of filters would be by the following edits:

    right after line 111, add the extra parameter by getting the count straight from the plugin

    Dim _Param As New Ext.Net.Parameter
    _Param.Name = "filters"
    _Param.Value = "Object.keys(App.mwgrid.filterHeader.getValue()).length"
    _Param.Mode = ParameterMode.Raw
    _button.DirectEvents.Click.ExtraParams.Add(_Param)
    lines 132-140 (the Click handler) becomes a simple echo of the passed value:

    Private Sub Click(sender As Object, e As DirectEventArgs)
        aktTextBox.Text = e.ExtraParams("filters")
    End Sub
    Likely, you're not interested in a flattened count of filters, but the object with keys and values. For that, you can use Client-side JSON techniques (Ext.encode for one alternative) to serialize (turn into a string) the object being passed as ExtraParam by clicking the button, then deserialize it from the e.ExtraParam("filters") output.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks, but where can I find the documentation about the function "filterheader"?

    I also need Information about GridPanel.getRecordsValues.

    Thanks Gidi
  4. #4
    Hello again, Gidi!

    Good question! The bad news is, there won't be documentation for this in the Sencha docs website, and I'm afraid the plugin code does not employ inline documentation directives.

    The good news though is that we have several examples showing usage of virtually all aspects of the plug in. And the actual client-side plugin code is not really very long, if the examples don't clear in the usage of some aspects, a quick read could help understand what's to be expected from a given portion.

    Here's a handy link for the formatted code of the Filter Header Plug In from our GitHub repository where we host speed.ext.net, which Ext.NET uses when resources source is set for CDN: ext.net/5.3.0/ux/filterheader/filterheader-debug.js.

    And, as always, we're here if you need help with specific scenarios you need to cover and for one reason or another couldn't figure out how to make it work.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hi Fabrício

    sorry for not replying for so long. I will try different things. I'll report back if I have problems.

    Tanks
    Gidi
  6. #6
    Hello agian, Gidi!

    Don't worry, take your time! We'll be here shall you need help with this in the future. We'll mark this thread as closed by now, but feel free to post back here if you have a follow-up regarding this subject, or create a new thread if you feel it's the case.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 0
    Last Post: Oct 19, 2017, 8:59 AM
  2. [CLOSED] Filters
    By Vamsi in forum 3.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 11, 2015, 8:51 AM
  3. [OPEN] [#325] Filters not clearing
    By paulc in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 19, 2013, 9:26 AM
  4. Replies: 3
    Last Post: Jan 12, 2012, 3:26 PM
  5. Filters for DataView?
    By shaun in forum 1.x Help
    Replies: 10
    Last Post: Jul 24, 2009, 5:05 PM

Posting Permissions