views:

157

answers:

1

Hi, I have a small flex datagrid. The dataProvider is an xmlList. I have two columns, userList and user permissions. The user permissions column as checkboxes. The values for the checkbox are stored as 0 and 1 in mySQL. While returning it from PHP, I am converting them to true or false. Its returning the values correctly to the frontend.

But inside the itemrenderer, the checkbox is not being set to true or false. Either everything is true or everything is false.

Here is my code. http://www.freeimagehosting.net/uploads/4ba76933d3.gif

How can I correctly set the value of the checkboxes from the DB values?

Please help.

+1  A: 

Change

<mx:CheckBox selected="{data.@selected}"/>

to

<mx:CheckBox selected="{Boolean(Number(data.@selected))}"/> (corrected thanx to Amarghosh)

and it should work fine.

Ladislav
I'd use `selected="{Boolean(Number(data.@selected))}"` or `{data.@selected == "1"}` to be sure. The string `"0"` (like any other non empty string) evaluates to `true` in javascript (and most certainly in actionscript too).
Amarghosh
I missed that he had 0, 1 as possibilities, my solution was if PHP returned true and false strings :)
Ladislav
Hey thanks a lot Ladislav and Amar. selected="{Boolean(Number(data.@selected))}" worked.
Vish
Again, the string `"false"`, like any other non empty string, evaluates to boolean `true`. Try this code and see it for yourself `if("false") alert("true"); else alert("false");`
Amarghosh
Oh, damn, tested it with Boolean('true') and not with Boolean('false')...just goes to show you have to test every case :)Thanx
Ladislav
Once the user sets some checkboxes, what is the best way to save these values back to the database? We use a WAMP server as backend.Thanks.
Vish
Probably using XML or JSON and send the data to PHP which than updates the database...
Ladislav
@Ladislav Edge cases.. they never stop coming! +1 :)
Amarghosh