4 Replies Latest reply on Mar 30, 2009 3:14 AM by atta707

    filter datagrid using search

    ww00
      hye...can anyone help me...

      how to filter a datagrid using search function?

      i have been doing some search,but nothing work...can someone show me??here,i attach my codes

      any help would be really appreciated

      thanks in advance.
        • 1. Re: filter datagrid using search
          _Natasha_ Level 4
          Hi.
          If you use XMLList type for DataGrid dataProvider you should manualy set myGrid.dataProvider = dg after you have change dg. Or you can use XMLListCollection instead.

          And i cann't understand why you use xml for data storing.
          It seems to be easier to use ArrayCollectionList for storing your LogReaders and use filters there.
          • 2. Re: filter datagrid using search
            atta707 Level 2
            Without looking at your code, here are few pointers:

            1) Take a look at filterFunction property of your ArrayCollection
            2) Remember to call ArrayCollection.refresh() everytime you set or clear the filterFunction property

            Here is working code, basically on every keystroke of your search input box, or whatever event you like to choose, you cann filterList function that sets the filterFunction property of array collection, that implements ICollectionView, to the local filter function that provides the logic for including the rows in the filtered view:

            private function filterList(event:Event) : void {
            var view:ICollectionView = this.dataGrid.dataProvider as ICollectionView;

            if (view.filterFunction == null) {
            this.totalRows = view.length;
            }

            if (!view) return;

            if (this.searchTextInput.text.length == 0) {
            view.filterFunction = null;
            view.refresh();
            return;
            }

            view.filterFunction = filter;
            view.refresh();
            }
            private function filter(item:Object) : Boolean {
            var s:String = ObjectUtil.toString(item, null, ['mx_internal_uid', 'Pretty Print', '#']);
            // trace(s);
            return s.indexOf(this.searchTextInput.text) >= 0;
            }
            • 3. Re: filter datagrid using search
              ww00 Level 1
              hye...can you give me more detail on this??i have tried to implement your code and i get these errors:

              -Access of undefined property ObjectUtil.
              -Access of possibly undefined property totalRows through a reference with static type Project.
              -Access of possibly undefined property dataGrid through a reference with static type Project.

              hope you can help..i'm new to this...

              thanks in advance
              • 4. Re: filter datagrid using search
                atta707 Level 2
                You should remove the implementation of the filter(item:Object) function and instead give your own implementation that returns false if current row, passed in as item parameter, should be filtered.