Categories | Question details Back To List | ||
dhtmlxgrid doesn't dispaly data... so -- I'm trying to use your grid, and it looks really cool, but I can't get data to load. See : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="STYLESHEET" type="text/css" href="codebase/dhtmlxcalendar.css"> <link rel="STYLESHEET" type="text/css" href="http://corp.contactpointsolutions.com/templates/rt_versatility_iii_j15/css/form.css"> <link rel="STYLESHEET" type="text/css" href="codebase/dhtmlxgrid.css"> <link rel="STYLESHEET" type="text/css" href="dhtmlxgrid_skins.css"> <script src="codebase/dhtmlxcommon.js"></script> <script src="codebase/dhtmlxgrid.js"></script> <script src="codebase/dhtmlxgridcell.js"></script> <script src="codebase/dhtmlxcalendar.js"></script> <script src="codebase/dhtmlxtabbar_start.js"></script> <script src="codebase/json2.js"></script> <script type="text/javascript" src="prototype.js"></script> <script> var dGrid; var JSONObj; function doInitGrid() { dGrid = new dhtmlXGridObject('gridbox'); dGrid.setImagePath("codebase/imgs/"); dGrid.setHeader("userID,Start,Deadline,Purpose,Risk,Completed"); dGrid.setColTypes("ro,ro,ro,ro,ch"); dGrid.setInitWidths("130,130,130,*,*,110"); dGrid.init(); dGrid.setSkin("modern"); requestGoals(); alert("Grid complete"); } function sendRequest() { new Ajax.Request("test1.php", { method: 'post', postBody: 'deadline='+$F('deadline')+"&purpose="+$F('purpose')+"&risk="+$F('risk'), onComplete: showResponse }); } function parse(s) { //I have to do this, because the php server doesn't have JSON enabled at the moment... j = new Array; t = s.split("?"); if(t[0] == 'success') { limit = t[1]; rows = t[2].split('@'); for (iter = 0; iter <= limit; iter++) { row = rows[iter].split('&'); j[iter] = new Object; j[iter].userID = row[0]; j[iter].sDate = row[1]; j[iter].deadline = row[2]; j[iter].purpose = row[3]; j[iter].risk = row[4]; j[iter].completed = row[5]; } } return j; } function requestGoals(){ new Ajax.Request("test1.php", { method: 'post', postBody: 'cmd=getGoals', onComplete: getData }); } function getData(rval) { JSONObj = parse(rval.responseText); alert("JSONObj ="+JSON.stringify(JSONObj)); // Note -- presents a message box that contains the JSON Object. dGrid.clearAll(); dGrid.parse(JSONObj, 'json'); // but the grid never displays the data, in firebug, the grid shows initialized, but remains blank on the screen } function showResponse(req) { JSONObj = new Array; retVALUE = req.responseText; retArray = retVALUE.split("?"); if (retArray[0] == 'success') { limit = retArray[1]; rows = retArray[2].split('@'); for (iter = 0; iter <= limit; iter++) { row = rows[iter].split('&'); JSONObj[iter] = new Object; JSONObj[iter].userID = row[0]; JSONObj[iter].sDate = row[1]; JSONObj[iter].deadline = row[2]; JSONObj[iter].purpose = row[3]; JSONObj[iter].risk = row[4]; JSONObj[iter].completed = row[5]; } } dGrid.parse(JSONObj, 'json'); } function getDeadline() { cal1 = new dhtmlxCalendarObject('deadline'); } </script> </head> <body onLoad="doInitGrid()"> <div id="gridbox" width="75%" height="250px"></div> <form id="mypurpose" onsubmit="return false;"> <fieldset><legend>What is Your Intention?</legend> <div class="notes"> <h4>Enter the Information for this month's Purpose.</h4> <p>Enter your purpose, what you're willing to risk for it, and your deadline.</p> </div> <div class="required"> <label for="deadline">Deadline :</label> <input name="deadline" id="deadline" class="inputText" size="10" maxlength="10" value="" readonly="true" type="text" onClick="getDeadline()"> </div> <div class="required"> <label for="purpose">What is your purpose for the month?</label> <input name="purpose" id="purpose" class="inputText" type="text"/> </div> <div class="required"> <label for="risk">What are your willing to risk to acheive this?</label> <input name="risk" id="risk" class="inputText" type="text"/> </div> <input type="submit" value="submit" onClick="sendRequest()"> </filedset> </form> <div id="show"></div> </body> </html> Answer posted by dhxSupport on Feb 26, 2009 01:57 You code seems right. Please check if you JSON structure is correct. Or try to load data to grid with JSON string: dGrid.parse(JSON.stringify(JSONObj), 'json') If issue still occurs please contact support@dhtmlx.com and provide sample where this issue occurs included files which you are using to initialize grid. Please note, loaded data from JSON supported from dhtmlxGrid version. 1.6+ |