Changing grid row value

Hi,

I’m trying to change values on a column cells. Like in this example,

http://www.dhtmlx.com/docs/products/dhtmlxGrid/samples/01_cell_types/07_pro_excells_numberformat.html

I made my own function:

function eXcell_ednro(cell) { if (cell){ this.cell = cell; this.grid = this.cell.parentNode.grid; } this.edit = function(){} this.isDisabled = function(){ return true; } this.setValue=function(val){ //var cell_content = ''; dhtmlxAjax.get("./php/tab/reader/reader_target.php?ids="+val,function(data){ cell_content = data.xmlDoc.responseText; }); this.setCValue(cell_content); for now we just set value as it is } }

But the problem is, I can’t take the content of cell_content variable, because it’s undefined outside the dhtmlxAjax.get().

Can you give me another approach, or you can help me with me approach?

P.S.
My task is to show in a grid , from mysql/php, columns: command, reader_ids.
Reader_ids is looking like this: 1,2,3

Because I couldn’t find how to do this from mysql, I want to modified from js, to have readers names, not the id: Reader 1, Reader 2, Reader 3.

Regards,
Nicole

Hi
are trying to join 2 mysql tables?
So you have two tables, first with columns ‘command’ and ‘reader_ids’, second with ‘reader_ids’ and reader name, is that correct?
If yes could you provide sample data from tables?

Yes, I want tot make a join. My tables are:

command:

id,
type_id,
readers,
result,
error

reader:

id,
name

example of data in command(‘1’,‘1’,‘1, 2,3’,‘1’,‘ok’) where the 1,2,3 are id of the readers, and I want to show there Reader 1, Reader 2, Reader 3 which are the reader.name

Hi
Mysql does not have something like “split” function so my idea is that you can either:

  • Create your own mysql function
    or
  • Join fielsd in PHP like:

1)create arrays from sql query

[code]$sqlCommand=mysql_query(“select * from command”)or die (mysql_error());
$sqlReader=mysql_query(“select * from reader”)or die (mysql_error());

$i=0;
while(mysql_fetch_assoc($sqlReader))
{
$array[mysql_result($sqlReader,$i,0)]=mysql_result($sqlReader,$i,1);
$i++;
}
$i=0;
while(mysql_fetch_assoc($sqlCommand))
{
$arrayc[mysql_result($sqlCommand,$i,0)]=array(“type_id” => mysql_result($sqlCommand,$i,1),“reader” => getReader(mysql_result($sqlCommand,$i,2),$array),“result” => mysql_result($sqlCommand,$i,3),“error” => mysql_result($sqlCommand,$i,4));
$i++;
}[/code]

  1. use function to get the real names
/**
 *  function return names from array
 *  $string - string from sql with keys
 *  $array - array of names
 */
function getReader($string,$array){
  $string=explode(",",$string);
  foreach ($string as $str){
    $reader[]=$array[$str];
  }
  return implode(",",$reader);
}

(code above might not be the prettiest :slight_smile: )

I suggest to you to store data differently. Instead of store (‘1’,‘1’,‘1,2,3’,‘1’,‘ok’) store this:
Reader 1 (‘1’,‘1’,‘1’,‘1’,‘ok’)
Reader 2 (‘1’,‘1’,‘2’,‘1’,‘ok’)
Reader 3 (‘1’,‘1’,‘3’,‘1’,‘ok’)

and if you want to get all those three readers together in one row, you can use concat function

concat_ws(", ",readers)
or
GROUP_CONCAT( readers ORDER BY command.readers separator ’ ') … group by id

Hope it helps