1

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!

Leigh
  • 28,765
  • 10
  • 55
  • 103
weggie
  • 427
  • 1
  • 10
  • 26

2 Answers2

2

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.

abbottmw
  • 752
  • 1
  • 5
  • 19
  • Ok, just tried this and it didn't work. I will try to use the example listed in the Docs to see if I can manually make it happen and look into writing something that will convert data to the format that it wants. I will also look into using JSON as well. It's a bit of a learning cure all at once. Trying to work on one thing at a time before abandoning it for something else. Thanks! Will report back on my findings. – weggie Mar 20 '13 at 13:30
2

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");

genericHCU
  • 4,394
  • 2
  • 22
  • 34
  • Thanks for all of the tips. Will be trying these suggestions this morning and reporting back. I really appreciate you all taking time to think about an answer the question. – weggie Mar 20 '13 at 12:17
  • Thanks, Looks like I'm just going to write something to spit out HTML – weggie Mar 21 '13 at 16:13
  • @weggie by 'spit out HTML' do you mean something like `toscript` in the page containing the grid or do you mean a flat HTML table? There are other grids out there if this one is giving you fits. – genericHCU Mar 21 '13 at 16:54
  • Travis, I guess the best case scenario would be to have the query converted to XML or to JSON. This will require some more work but please let me know what other grids you are suggesting. I'll gladly take a look. – weggie Mar 22 '13 at 11:58
  • @weggie any of these should work, depending on your requirements http://stackoverflow.com/a/5780573/244136 – genericHCU Mar 22 '13 at 12:30