Question

I was hoping to get pushed into the right direction for this great product.

What I would like to do is run a query or stored procedure, get the resulting data set and then have the results formatted for use in dhtmlxGrid. I don't need to write data back to the DB I am just need to display them.

I have gotten the demo to work with basic text and the xml file

(http://docs.dhtmlx.com/doku.php?id=tuto ... populating)

However, is there a way to take the query results and pass them directly to dhtmlxGrid directly without having to write the data to a file and then reading it?

I have tried something like this:

var mygrid;
function doInitGrid(){

mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.setImagePath("codebase/imgs/");
mygrid.setHeader("Model,Qty,Price");
mygrid.setInitWidths("*,150,150");
mygrid.setColAlign("left,right,right");
mygrid.setSkin("light");
mygrid.init();
mygrid.parse(<cfoutput>#xmlString#</cfoutput>);

xmlString is a valid XML object but the grid does not format like this. The source comes out like this:

var mygrid;
function doInitGrid(){

mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.setImagePath("codebase/imgs/");
mygrid.setHeader("Model,Qty,Price");
mygrid.setInitWidths("*,150,150");
mygrid.setColAlign("left,right,right");
mygrid.setSkin("light");
mygrid.init();
mygrid.parse(<?xml version="1.0" encoding="UTF-8"?>
<users columns="3" rows="3"><user fname="Nathan" id="292B71DC-9DDD-BA4F-    A95BF84F85CAF661" lname="Dintenfass"/><user fname="Ben" id="292B71DD-0893-326D-    79269A1DCFD46D37" lname="Archibald"/><user fname="Raymond" id="292B71DE-E781-43FE-    A4DCD955A1A5C044" lname="Jones"/></users>);

}

Thanks in advance!

Was it helpful?

Solution

In addition to Abbottmw's jsStringFormat suggestion, notice he wrapped the ColdFusion output in quotes which are required but missing from your code.

If the XML isn't working out for you, you could probably load it using JSON created with ColdFusion's SerializeJSON or use a CFC with the function's returnformat="JSON" and this JSON spec in DHTMLX or load from an array using toScript from ColdFusion.

However, is there a way to take the query results and pass them directly to dhtmlxGrid directly without having to write the data to a file and then reading it?

Definitely. From the JSON loading instructions:

To load data from a remote file (a static JSON file or any kind of script that will generate json output) the following code strings should be used:

That means something as simple a .cfm or .cfc (recommended) page that generates the json output dynamically. For example, If you used a CFC with a function called dhtmlxJSON, you would call it like this in your grid. grid.load("myJsonGenerator.cfc?method=dhtmlxJSON","json");

OTHER TIPS

You could try wrapping your #xmlString# in JSStringFormat()

mygrid.parse('<cfoutput>#JSStringFormat(xmlString)#</cfoutput>');

I would look at the XML Syntax documentation on how the XML should be structured.

You would need to write a custom function to take a query and convert it over to the XML Syntax that the dhtmlx is expecting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top