No output from beforeOutput event

Hi

I am storing the grid config in a JSON file on the server. I want to include the contents of that file with the data. I am using the beforeOutput event to insert the config data (per the sample code) but it is not being sent. Only the actual data is being sent. I have tried a number of things like including the data in my beforeOutput output but nothing I echo gets outputted.

The doco says that the beforeOutput event gets no parameters however Stan has mentioned in this forum that it gets the connector and the data. That does not seem to be correct.

Anyway my key objective is to include the config from a file in the data output of the render.
How can I do that please.

My sample code is:

[code]require_once(“codebase/data_connector.php”);
require_once(“codebase/db_mysqli.php”);

function outputHeader($conn, $data){
LogMaster::log(“I arrived in outputHeader”);

echo "{head:[ 
		{id:'deviceID',    width:105,  type:'ro',   		align:'left',  sort:'str', value:'device'}, 
		{id:'displayName',    width:100, type:'ro',    align:'left',   	sort:'str', value:'U(device)U'}, 
		{id:'lastContact',   width:70, type:'ro',   		align:'left',   	sort:'date', value:'T(lastcontact)T'}, 
		{id:'expirationTime',    width:70,  type:'ro', 	align:'left',  sort:'date', value:'T(expires)T'}, 
		{id:'licensePlace',  width:'*',  type:'ro',    	align:'left', sort:'str', value:'T(licenseplate)T'} 
		], rows: $data }";
return false;

};

function navListComplexSql($sql, $key, $list){
global $acc, $dbh;
$gridConn = new JSONDataConnector($dbh, “MySQLi”);
$gridConn->enable_log(“navList.log”);
LogMaster::log(“any text here”);
$gridConn->event->attach(“beforeOutput”,“outputHeader”);
$gridConn->filter(“accountID”, $acc);
$gridConn->render_complex_sql($sql,$key,$list);
}
function navListComplexSql($sql, $key, $list){
global $acc, $dbh;
$gridConn = new JSONDataConnector($dbh, “MySQLi”);
$gridConn->enable_log(“navList.log”);
LogMaster::log(“any text here”);
$gridConn->event->attach(“beforeOutput”,“outputHeader”);
$gridConn->filter(“accountID”, $acc);
$gridConn->render_complex_sql($sql,$key,$list);
}

navListComplexSql($sql,“deviceID”, “deviceID, displayName, lastContact, expirationTime, licensePlate”);

[/code]

Hi,

Connector will block all output by “echo” command ( it necessary to prevent any debug or unwanted output during data generation )

You can change your code like next

[code]function outputHeader($conn, $data){
LogMaster::log(“I arrived in outputHeader”);
$text = “”.$data;

$data->reset();
$data->add("{head:[
{id:‘deviceID’, width:105, type:‘ro’, align:‘left’, sort:‘str’, value:‘device’},
{id:‘displayName’, width:100, type:‘ro’, align:‘left’, sort:‘str’, value:‘U(device)U’},
{id:‘lastContact’, width:70, type:‘ro’, align:‘left’, sort:‘date’, value:‘T(lastcontact)T’},
{id:‘expirationTime’, width:70, type:‘ro’, align:‘left’, sort:‘date’, value:‘T(expires)T’},
{id:‘licensePlace’, width:’*’, type:‘ro’, align:‘left’, sort:‘str’, value:‘T(licenseplate)T’}
], rows: $text }");
};[/code]

thanks Stanislav

This worked and the config of the grid works however the data does not display. A sample of the data from the output of the php looks like:

{ skin: "dhx_skyblue", icons_path: "imgs/", image_path: "lib/dhtmlx/imgs/", head: [{ id: "userID", width: 90, type: "ro", align: "left", sort: "str", value: "T(driver)T ID" }, { id: "description", width: "*", type: "ro", align: "left", sort: "none", value: "T(name)T" }], rows: [{ "id": "dragon7752@gmail.com", "userID": "dragon7752@gmail.com", "description": "Paul McCann" }, { "id": "gmax", "userID": "gmax", "description": "Grant Maxwell" }] }

A sample I found online suggests the data should look more like:

rows:[ { id:1001, data:[ "100", "A Time to Kill", "John Grisham", "12.99", "1", "05/01/1998"] },

regards
Grant

Change ], rows: $text }"); to ], data: $text }");

And on client-side, you need to use

grid.load(url, "js"); //js, not json

There are two different json formats that can be used. “json” is a json specific for the grid, “js” is a common json (array of objects)

Thanks Stanislav

Everything is now working well. Using this method has allowed us to reduce our UI code by hundreds of lines by creating reusable DHTMLX Grid objects and PHP connector scripts. Of course it has also reduced the number of potential programmer errors.

thanks for the help

regards
Grant