5 Replies Latest reply on Jan 12, 2009 12:14 AM by Richard_Abbott

    Filtering a Datagrid with Multiple Selections

    funnyduddy
      Hi,

      I'm trying to filter a datagrid using togglebutton bars and sliders. I've coded it and it filters fine but say I have one button bar with these options...

      COLOUR
      All, Blue, Red, Green, Yellow

      And then have another with

      MATERIAL
      All, Plasic, Metal, Glass

      Then a slider

      SIZE

      1cm, 2cm, 3cm, 4cm.

      Say I wanted to show all items that are blue that are plastic and are 4cm. I select them using my options but each option cancels the other one out for example when I click plastic it filters out all items not plastic then I select blue but it then show all the other materials too including metal etc...

      Here is my code...

      Thanks
        • 1. Re: Filtering a Datagrid with Multiple Selections
          Richard_Abbott Level 3
          Surely the problem is that you ar each time replacing the filter function. Why not have either
          a) a single filter function that identifies your current selections and applies all of them, or
          b) use your variables selectedMaterial etc in all of the filter functions and if not set to "all" or equivalent do a logical test including this.

          Richard
          • 2. Re: Filtering a Datagrid with Multiple Selections
            funnyduddy Level 1
            Thanks Richard I thought it might be something to do with that

            I wouldn't know where to start on implementing your two options lol, I still a huge newbie to this flex and even programming malarky.
            • 3. Re: Filtering a Datagrid with Multiple Selections
              Richard_Abbott Level 3
              Hi funnyduddy,
              replace your function
              public function materialFilterFunc(item:Object):Boolean {
              if (selectedMaterial=="All")
              return true
              else
              return item.material == selectedMaterial;
              }

              with
              public function materialFilterFunc(item:Object):Boolean {
              var mat_sel: Boolean;
              var col_sel: Boolean;
              if (selectedMaterial=="All")
              mat_sel = true
              else
              mat_sel = (item.material == selectedMaterial);
              if (selectedColour=="All")
              col_sel = true
              else
              col_sel = (item.mat == selectedColour);

              return mat_sel && col_sel;
              }

              and of course similar for the other filter functions, and you'd want to check I have got your variable names correct. That would do option (b). Hope that helps!

              Richard
              • 4. Re: Filtering a Datagrid with Multiple Selections
                funnyduddy Level 1
                Thanks richard this seems to work kind of but for some reason the first selection I make e.g blue it displays none but by selecting other options e.g plastic then click blue the blue plastic ones appear. Its quite strange.

                Also how would it work with slider options?

                Thanks again
                • 5. Re: Filtering a Datagrid with Multiple Selections
                  Richard_Abbott Level 3
                  funnyduddy,
                  back after the weekend... sounds to me like you need to add some initialisation of your variables, eg
                  selectedMaterial = "All";
                  selectedColour = "All";
                  in your init() handler. For the slider, you need to decide what the default range value (the equivalent of "All") should be. At a guess it might be easiest to have a special value like -1 that flags up that you want all items, but maybe there's a better way given what your interface looks like, perhaps a checkbox beside the slider?
                  Richard