Re: Dynamically create Select criteria
- To: mathgroup at smc.vnet.net
- Subject: [mg125405] Re: Dynamically create Select criteria
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Mon, 12 Mar 2012 04:09:14 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201203091110.GAA26899@smc.vnet.net>
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 <ejmcinerney 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
- References:
- Dynamically create Select criteria
- From: Jack McInerney <ejmcinerney@gmail.com>
- Dynamically create Select criteria