8 Replies Latest reply on Jul 6, 2006 1:55 AM by Edbras

    hidding row data in datagrid?

    Edbras
      How can I hide rows in a datagrid?... in an efficient way ?
      What I have: a collection bindable to a datagrid.

      However, when the user presses a day in a calendar I want to show only the rows that have a matching date property.

      I don't want to remove data objects from the orginal collection that is the data provider. So is their a way of hidding the data?

      Another way is by copying the collection and removing the objects that doesn't match the date property, and make that the data provider. But that's not so efficient, is it ?? :(...

      Please some feedback.
        • 1. Re: hidding row data in datagrid?
          inlineblue Level 1
          I think you're better off just creating a new dataprovider. However, don't copy the entire original collection. Loop through it and copy out just the ones that match your filter.
          • 2. Re: hidding row data in datagrid?
            Edbras Level 1
            Hmmmm... I was afraid of that :(... couldn't realy find anything...

            It would be nice to have a kind of datadescriptor constructor just like the Tree data descriptor whereby you can indicate if the element must be included in the datagrid or not... and as such you can hide data, kind of view on the total data.
            • 3. Re: hidding row data in datagrid?
              Flex harUI Adobe Employee
              I'm not clear why you can't use a filter on the collection.
              • 4. Re: hidding row data in datagrid?
                Edbras Level 1
                Thanks for the reply.
                Can you explain this in more detail?

                I mean, I passed byt filters when I was looking for a solution, but thought that this contains filters for visual effects, like the dropshadow?

                Where do I find more information of this?
                • 5. Re: hidding row data in datagrid?
                  Flex harUI Adobe Employee
                  Sorry, there are several kinds of filters. The one I'm talking about is ICollectionView.filterFunction. It is a function you set on the ArrayCollection that returns true if the collection item should be in that "view" of the data.
                  • 6. Re: hidding row data in datagrid?
                    Edbras Level 1
                    Ok thanx a lot.
                    I will have a lot at it.
                    • 7. Re: hidding row data in datagrid?
                      TIPLVinay Level 1
                      a filter example:-

                      function doPackFilter(dg:mx.controls.DataGrid)
                      {
                      var filteredRecords = new Array();// new dataprovider

                      var filterText :String = pack_code.text;.// text entered by user

                      for(var i = 0; i < dg.dataProvider.length; i++ )
                      {
                      var curRecord = dg.dataProvider
                      var name : String = curRecord.code;
                      //Filter on code column of DG
                      if(name.substring(0, filterText.length) == filterText)
                      {
                      filteredRecords.push(curRecord);
                      }
                      }
                      dg.dataProvider = filteredRecords;
                      }


                      beside this if u wanna show all records simply switch to old dataprovider
                      • 8. Re: hidding row data in datagrid?
                        Edbras Level 1
                        I use the filterfunction on the ArrayCollection through the ICollectionView interface like someone advises above. That works really well:

                        var col:ArrayCollection = ArrayCollection(this.mainPanel.DataGridLijst.dataProvider);
                        col.filterFunction = this.filterDate;
                        col.refresh();

                        And the filterDate function returns an Array, the same length as the orignal datagrid dataprovider, something like this:
                        private function filterDate (item:Object):Boolean {
                        trace("[Filter datagrid collection], object: " + item);
                        // do something and retun true or false
                        return false;
                        }

                        Sot his method is called for every datagrid row when we call a refresh() and if it returns false the row will not be shown, simple ;)