Re: [flexcoders] Re: filter arraycollection with checkbox acting wired
Can you click on the checkbox more than once (let's say 5 times) and resend the output? Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Tue, Feb 17, 2009 at 8:57 AM, johndoematrix johndoemat...@yahoo.comwrote: when i replace the code and run the app, i get the following output when i click the pizza_ckb checkbox and all the info disappears [SWF] /IE_V1/bin/portal_V1-debug.swf - 2,109,478 bytes after decompression true
[flexcoders] Re: filter arraycollection with checkbox acting wired
sorry i had forgotten to trace the item.pool. anyhow when i do that and i click the check box once i get true false true false true true when i click five times i get true false true false true true false false true false true true true false true false true true false false true false true true true false true false true true
Re: [flexcoders] Re: filter arraycollection with checkbox acting wired
It seems like your data is OK. So I did a test application and I figured out that the filter function is wrong. It should only do the test if the checkbox is selected, otherwise it should always return true because in this case you want display all items. So here is my working test app, I hope you can use it to make your code work: ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=vertical mx:Script ![CDATA[ private var pizzaSelected:Boolean = false; private function pizzaFilter():void { pizzaSelected = pizza_ckb.selected; pizzaAr.refresh(); } private function myFilterFunction(item:Object):Boolean { if (pizzaSelected) return (item.pizza == pizzaSelected); else return true; } ]] /mx:Script mx:ArrayCollection id=pizzaAr filterFunction=myFilterFunction mx:Object label='Pizza 1' pizza='true' / mx:Object label='Not a pizza 1' pizza='false' / mx:Object label='Pizza 2' pizza='true' / mx:Object label='Pizza 3' pizza='true' / mx:Object label='Not a pizza 2' pizza='false' / /mx:ArrayCollection mx:CheckBox id=pizza_ckb change=pizzaFilter() / mx:List dataProvider={pizzaAr} labelField=label / /mx:Application Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Tue, Feb 17, 2009 at 9:09 AM, johndoematrix johndoemat...@yahoo.comwrote: sorry i had forgotten to trace the item.pool. anyhow when i do that and i click the check box once i get true false true false true true when i click five times i get true false true false true true false false true false true true true false true false true true false false true false true true true false true false true true
[flexcoders] Re: filter arraycollection with checkbox acting wired
Thanks Ben will let you know if it was successful, but am confident that this will work given your explanation.
[flexcoders] Re: filter arraycollection with checkbox acting wired
hi Ben when i tried the solution you gave, it worked very very well. but this is when am using a single criteria. when i try to add it to a filter function that filter's based on more than one criteria that's when there come's a problem.
[flexcoders] Re: filter arraycollection with checkbox acting wired
This is asolutely comical. -TH --- In flexcoders@yahoogroups.com, johndoematrix johndoemat...@... wrote: hi Ben when i tried the solution you gave, it worked very very well. but this is when am using a single criteria. when i try to add it to a filter function that filter's based on more than one criteria that's when there come's a problem.
RE: [flexcoders] Re: filter arraycollection with checkbox acting wired
I've quit this one. The original poster needs to develop his debugging techniques before going any further. Tracy Spratt Lariat Services Flex development bandwidth available From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Tim Hoff Sent: Tuesday, February 17, 2009 12:57 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: filter arraycollection with checkbox acting wired This is asolutely comical. -TH --- In flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com , johndoematrix johndoemat...@... wrote: hi Ben when i tried the solution you gave, it worked very very well. but this is when am using a single criteria. when i try to add it to a filter function that filter's based on more than one criteria that's when there come's a problem.
Re: [flexcoders] Re: filter arraycollection with checkbox acting wired
You have to review the logic of your filter function. As Tracy said, you should try to debug, this will save you a lot of time. Put a break point in the filter function and test your conditions. Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Tue, Feb 17, 2009 at 1:23 PM, johndoematrix johndoemat...@yahoo.comwrote: hi Ben when i tried the solution you gave, it worked very very well. but this is when am using a single criteria. when i try to add it to a filter function that filter's based on more than one criteria that's when there come's a problem.
[flexcoders] Re: filter arraycollection with checkbox acting wired
Hi, There's a few problems with your original code. First, pizzaSelected will never change after the first click of the CheckBox; because you're only setting it if the CheckBox is selected. Also not sure why you don't just use pizzaSelected = pizza_ckb.selected; instead of pizza_ckb.data, or why use a reference variable at all. Second, you're trying to compare String values to Boolean values. Boolean values are sometimes stored as varchar, int, or bit in a database. Once the data gets to the client, you need to make sure that you are either casting these values to Boolean, or comparing them to similar data types; in this case it looks like String. If you are using strings, also be careful of spelling and case. Finally, you only need to use refresh() once; after a sort or filterFunction has been applied to a collection. Give this code a whirl: private var pizzaSelected:String; private function pizzaFilter():void { pizzaSelected = pizza_ckb.selected ? yes : no ; filterGrid(); } private function filterGrid() :void { // this assumes that you want to show all; if pizza_chb is not selected pizzaAr.filterFunction = (pizzaSelected == yes) ? myFilterFunction : null; pizzaAr.refresh(); } private function myFilterFunction(item:Object): Boolean { return (item.pizza.toLowerCase() == pizzaSelected) ; } -TH --- In flexcoders@yahoogroups.com, johndoematrix johndoemat...@... wrote: i have tried every advise provide so far and still doesn't work. this is the senario, in my database i have a column(Field Name) for pizza with Data Type YES/NO. i display everything in a flex app through a arraycollection and want to filter that data. i use a checkbox to filter data if there is pizza or not. when the pizza checkbox is checked i want to show only entries with pizza. hope that details what i wanna do.
[flexcoders] Re: filter arraycollection with checkbox acting wired
Hi, Tim i tried your code, but the result is not good too. when then check box is checked, all the data in the array collection disappears and when its unchecked all data shows up again. what i want to achieve is when the pizza_ckb is checked only the entries in the data base that have pizza show up and when i uncheck it all entries with or without pizza show up. thanks
Re: [flexcoders] Re: filter arraycollection with checkbox acting wired
Replace the following functions, run the app in debug mode and post the output: private function pizzaFilter():void { trace(pizza_ckb.selected); if ( == true) pizzaSelected = pizza_ckb.data; filterGrid(); pizzaAr.refresh(); } private function myFilterFunction(item:Object): Boolean { trace(item.pizza); return (item.pizza == pizzaSelected) ; } Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Tue, Feb 17, 2009 at 7:44 AM, johndoematrix johndoemat...@yahoo.comwrote: Hi, Tim i tried your code, but the result is not good too. when then check box is checked, all the data in the array collection disappears and when its unchecked all data shows up again. what i want to achieve is when the pizza_ckb is checked only the entries in the data base that have pizza show up and when i uncheck it all entries with or without pizza show up. thanks
[flexcoders] Re: filter arraycollection with checkbox acting wired
when i replace the code and run the app, i get the following output when i click the pizza_ckb checkbox and all the info disappears [SWF] /IE_V1/bin/portal_V1-debug.swf - 2,109,478 bytes after decompression true
[flexcoders] Re: filter arraycollection with checkbox acting wired
i have tried every advise provide so far and still doesn't work. this is the senario, in my database i have a column(Field Name) for pizza with Data Type YES/NO. i display everything in a flex app through a arraycollection and want to filter that data. i use a checkbox to filter data if there is pizza or not. when the pizza checkbox is checked i want to show only entries with pizza. hope that details what i wanna do.
[flexcoders] Re: filter arraycollection with checkbox acting wired
can someone please help me out here..thanks
RE: [flexcoders] Re: filter arraycollection with checkbox acting wired
I think I suggested already that you just need to debug this. Find an item that does not filter as you expect, step through the code til you hit that item, then step through the code to see why the filter function is not returning the expected value. It will almost certainly be obvious. For us to help, we need to do that process a a thought experiment. It will be much easier for you do do it in the debugger. Tracy Spratt Lariat Services Flex development bandwidth available From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of johndoematrix Sent: Friday, February 13, 2009 10:54 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: filter arraycollection with checkbox acting wired can someone please help me out here..thanks
[flexcoders] Re: filter arraycollection with checkbox acting wired
hi tried all that but no head way. in my data base i have a pizza column which is either yes or no(yes/no) now i have some entries as yes and some as no so that when someone checks the checkbox it shows those items that are yes in the database. i am following this example, the difference is that for this the value is not Boolean as in yes or no. any help... ?xml version=1.0 encoding=utf-8? !-- http://blog.flexexamples.com/2008/03/12/using-a-combobox-to-filter-items-in-a-datagrid-in-flex/ -- mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=vertical verticalAlign=middle backgroundColor=white mx:Script ![CDATA[ import mx.controls.dataGridClasses.DataGridColumn; private function toggleFilter():void { if (checkBox.selected) { arrColl.filterFunction = processFilter; } else { arrColl.filterFunction = null; } arrColl.refresh(); } private function processFilter(item:Object):Boolean { return parseFloat(item.value) == 0; } private function value_labelFunc(item:Object, col:DataGridColumn):String { return item[col.dataField].toFixed(2); } ]] /mx:Script mx:ArrayCollection id=arrColl mx:source mx:Array mx:Object name=ColdFusion value=0.00 / mx:Object name=Dreamweaver value=0.12 / mx:Object name=Fireworks value=1.01 / mx:Object name=Flash value=0 / mx:Object name=Flash Player value=-0.00 / mx:Object name=Flex value=0.00 / mx:Object name=Illustrator value=2.92 / mx:Object name=Lightroom value=0.32 / mx:Object name=Photoshop value=0.06 / /mx:Array /mx:source /mx:ArrayCollection mx:Panel status={arrColl.length}/{arrColl.source.length} item(s) mx:DataGrid id=dataGrid dataProvider={arrColl} verticalScrollPolicy=on mx:columns mx:DataGridColumn dataField=name / mx:DataGridColumn dataField=value labelFunction=value_labelFunc / /mx:columns /mx:DataGrid mx:ControlBar mx:CheckBox id=checkBox label=Filter DataGrid click=toggleFilter(); / /mx:ControlBar /mx:Panel /mx:Application
[flexcoders] Re: filter arraycollection with checkbox acting wired
Hi, try private function myFilterFunction(item:Object): Boolean { trace(item.pizza + item.pizza); return (item.pizza == pizzaSelected) ; } Look at the console, maybe you have all item.pizza == false. Henrique F. Marino blog.dclick.com.br www.dclick.com.br --- In flexcoders@yahoogroups.com, Tracy Spratt tspr...@... wrote: Debug it. Does pizza_ckb.data contain what you expect? Is you filter function working correctly? Tracy Spratt Lariat Services Flex development bandwidth available From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of johndoematrix Sent: Monday, February 09, 2009 8:52 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] filter arraycollection with checkbox acting wired hi i am trying to filter an array collection using a checkbox, but when i select the check box all the data disappears. here is my filter function private var pizzaSelected:Boolean; private function pizzaFilter():void { if (pizza_ckb.selected == true) pizzaSelected = pizza_ckb.data; filterGrid(); pizzaAr.refresh(); } private function filterGrid() :void { pizzaAr.filterFunction=myFilterFunction; pizzaAr.refresh(); } private function myFilterFunction(item:Object): Boolean { return (item.pizza == pizzaSelected) ; } then on my pizza_ckb checkbox on the click event i call pizzaFilter(); is there something am doing wrong. if there is pizza then the result is true and pizza records show if false nothing is supposed to show up.