Login Register

Grid - Status of checkbox from a JSON store

A few days ago I started working with the Dojo toolkit and most things work out fantastically for me.

I'm using the Grid and populated it using a JSON-store (created from an MySQL-database using PHP). So far, so good. There are several boolean-fields; their values (in the JSON-file) are either '0' or '1'.

How can I get the dojox.grid.editors.bool-editor to work with these values? I don't want to change the database values from 1 to e.g. 'checked'.

Using
{name: 'Visible', field: "Visible", width: 3, styles: 'text-align: center;', editor: dojox.grid.editors.bool, value:'1' }
in my fields declaration for the grid doens't seem to work.

Thanks in advance for your replies.

I am having the same issue.

I am having the same issue. Is there another parameter that needs to be used? When I use grid.update(), the character fields are saved into the mysql database, but the boolean field isn't being saved.

Update

I asked on irc about this issue...

Basically, what you have to do is convert the mysql tinyint(1) (1 or 0) into json (true or false). I looked at the json.php code and saw that encode does a vartype() on the passed in value. Well, 1/0 is a number, not a bool, so you don't get what you expect. There must be a forced conversion somewheres that looks at the field definition maybe.

I'm going to play around with mysql to see if (in my case) another datatype can be used...

I am using mySql 5.0 if that matters.

Update 2

Okay, so I have half of this working so far. What I did was apply my lil conversion util right before the return in the "select" function in data.php

I changed the lasts line of the select function to this...

function select($inQuery = '') { 
...
               $result = getArray($result); 	
		$result = dgsConvert($result);		
		return $result;
}

And then added the function dgsConvert into data.php ....

function dgsConvert($aArray){	
		$cMyColumns = getColumns();		
		$nLenI = count($aArray);
		for ($i=0; $i < $nLenI; $i++){
			$nLenJ = count($aArray[$i]);			
			for ($j=0; $j < $nLenJ; $j++){
				$aArray[$i][$j] = ($cMyColumns[$j]->Type == "tinyint(1)" ? ($aArray[$i][$j] ? true : false) : $aArray[$i][$j]);
			}	
		}		
		return $aArray;		
	}

The only thing is I am assuming that ANY tinyint(1) is a mysql boolean. Serves my purpose...