Can´t load data into grid with JSON

Hi guys, I’m trying to load into Grid my Database data but I can´t.

I´m using CodeIgniter this is my JS code combined with Jquery:

$(document).on('click','#rhMenu',function(){ $('#workspace').html(''); $('#workspace').html('<center><div id="gridbox"></div></center>'); var path = CIPath+'Welcome/getUsers'; myGrid = new dhtmlXGridObject('gridbox'); myGrid.setHeader("ID, Name, Lastname"); myGrid.setInitWidths("70,250,*"); myGrid.setColAlign("right,left,left"); myGrid.setColTypes("ed,ed,ed"); myGrid.setColSorting("str,str,str"); myGrid.init(); myGrid.load(path,"json"); });

This is my controller on CodeIgniter

[code] public function getUsers()
{
$output = “”;
$result = $this->Welcomes_model->getUsersDB();
$res = $result->result();
$i = 1;
if($result->num_rows() > 0)
{
$output.=’
data={
rows:[’;
foreach($res as $key)
{
$output.=’{id:’.$i.’, data:["’.$key->id.’","’.$key->nombre.’","’.$key->apellidos.’"]},’;
$i++;
}

			$output.='
			]	
		};';
		
	}
	echo $output;
}[/code]

I tryed to create this code https://docs.dhtmlx.com/grid__data_formats.html#jsonformat exactly as I can and the output is this

data = { rows:[ {id: 1,data: ["1", "sys", "32"]}, {id: 2,data: ["95", "Pepe", "Botello"]}, {id: 3,data: ["98", "Isabel", "Uribe"]}, ] };

But it doesn´t work :frowning:
I’m new on DHTMLX if you can help me with this code or perform it.

Thanks so much

Please, try to use:

[code] public function getUsers()
{
$output = “”;
$result = $this->Welcomes_model->getUsersDB();
$res = $result->result();
$i = 1;
if($result->num_rows() > 0)
{
$output.=’
{
rows:[’;
foreach($res as $key)
{
$output.=’{id:’.$i.’, data:["’.$key->id.’","’.$key->nombre.’","’.$key->apellidos.’"]},’;
$i++;
}

        $output.='
        ]   
     };';
     
  }
  echo $output;

}[/code]