Re: Dynamically create Select criteria
- To: mathgroup at smc.vnet.net
- Subject: [mg125416] Re: Dynamically create Select criteria
- From: Jack McInerney <ejmcinerney at gmail.com>
- Date: Tue, 13 Mar 2012 03:04:05 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201203091110.GAA26899@smc.vnet.net> <jjkek8$1cb$1@smc.vnet.net>
On Mar 12, 2:11 am, Bob Hanlon <hanlonr... at gmail.com> wrote:
> data = {
> {"Fido", "dog", 8},
> {"Sparky", "dog", 2},
> {"Shadow", "cat", 1},
> {"Cuddles", "cat", 3},
> {"Cutey", "rabbit", 1}};
>
> types = Union[data[[All, 2]]];
>
> ages = Union[data[[All, 3]]];
>
> Manipulate[selection = Select[data,
> (age != {} || type != {}) &&
> (age != {} && type == {} ||
> MemberQ[type, #[[2]]]) &&
> (type != {} && age == {} ||
> MemberQ[age, #[[3]]]) &],
> {{type, {}, Style["Type", Blue, 12]}, types},
> {{age, {}, Style["Age", Blue, 12]}, ages},
> ControlType -> CheckboxBar]
>
> Dynamic[selection]
>
> Bob Hanlon
>
>
>
> On Fri, Mar 9, 2012 at 6:10 AM, Jack McInerney <ejmciner... at gmail.com> wrote:
> > I have a database in the form of a big list, and want to select a
> > subset of this list, by allowing the user to click on checkboxes. The
> > example below shows the idea. Given a list of animals, lets say I
> > want to select all the cats that are 1 year old, or all of the dogs
> > and cats. I can't figure out how to use the output of my checkboxes
> > to dynamically create a selection criteria for the Select function.
> > Is this possible? Any thoughts would be appreciated.
>
> > data={{"fido", "dog",8},
> > {"Sparky", "dog",2},
> > {"Shadow", "cat",1},
> > {"Cuddles", "cat",3},
> > {"Cutey", "rabbit",1}};
>
> > CheckboxBar[Dynamic[type], DeleteDuplicates[data[[All,2]] ]]
>
> > CheckboxBar[Dynamic[age], Sort[DeleteDuplicates[data[[All,3]] ]]]
>
> > Dynamic[Select[data, #[[2]]==type[[1]] && #[[3]]==age[[1]]&]] (*<--
> > criteria should depend on which boxes have been checked by user *)
>
> > Thanks,
> > Jack- Hide quoted text -
>
> - Show quoted text -
Hi Bob,
This is an amazing piece of Mathematica code you produced. It works
perfectly, but I have only a partial grasp on how it works. I will
need to study it some more. A lot more...
Jack
- References:
- Dynamically create Select criteria
- From: Jack McInerney <ejmcinerney@gmail.com>
- Dynamically create Select criteria