AnsweredAssumed Answered

Programmatically create a datagrid from the results of a querytask

Question asked by schlot on Aug 13, 2013
Latest reply on Jul 23, 2015 by schlot
I have set of functions that will execute a series of querytasks based on the current layer visibility.  Now I have a featureset from each querytask, all likely to have different field names, depending on which layer it's from.  This means I need to create both the data source and grid on the fly from the results.

Each queryTask should create one new titlePane in an existing floating pane, and each titlePane is the container for one datagrid. 
The title panes are getting added, but my datagrid isn't getting created properly, so the panes are just empty.  I think I'm so close, but I'm having problems getting all the pieces I need pulled together to properly create and populate the grid.

Elsewhere I created an array of the layer names from the query tasks, while those are getting set up.  I'm using this to have a 'real' name to my titlePane, since I don't see that the original layer name is anywhere in the featureset.  The div 'attributeDiv' existing already in my floatingPane.

function queryGeometryResultsHandler_toGrid(results, idx) {     var myDiv = dojo.byId("attributeDiv");     var currentLayerId = qTaskNameList[idx];  var paneTitle = (currentLayerId.split('_').join(' '));//earlier all spaces were replaced _, now I need spaces for the title  var tp = new dijit.TitlePane({ id: 'gridPane_'+currentLayerId, title: paneTitle});             myDiv.appendChild(tp.domNode);   var itemNames = [];   var featureAttributes =, function(feature){              return feature.attributes;  });       var firstFeature = featureAttributes[0];  for(var fieldName in firstFeature) {    itemNames.push(fieldName);   }   console.log(itemNames);           //gets the field names from the first feature for the grid  // for (fieldName in itemNames[0]) {  var currentLayout = [];  var addField;  dojo.forEach(itemNames, function (fieldName) {        /*     if (fieldName == "FID" || fieldName == "OBJECTID" ) {                 addField = { field: fieldName, formatter: makeZoomButton };                currentLayout.push(addField);              }*/             if (fieldName == "Shape" || fieldName == "FID" || fieldName == "OBJECTID") {                 addField = { field: fieldName, hidden: true };                 currentLayout.push(addField);             }  else {     //console.log("field Name is " + fieldName);                 addField = {                 field: fieldName,                 width: "120px"                };         currentLayout.push(addField);                  }             });     console.log(currentLayout);   var data = {    identifer: "OBJECTID",             items: featureAttributes         };                var currentStore = new{             data: data         });            // Create Grid    var grid = new dojox.grid.DataGrid({             id: currentLayerId+"_grid",             store: currentStore             }, document.createElement('div'));              grid.startup();   var currentPane = dojo.byId('gridPane_'+currentLayerId);            currentPane.appendChild(grid.domNode);   //  tp.appendChild(grid.domName);               // tp.set("content",grid);      // }  } 

1 - I'm not sure the datagrid has the right input to be correct.  Setting breakpoints, I see there is information in the variable 'currentStore'.
2- I'm not sure that appendChild is the correct command to add the grid to the newly created titlePane, so it might be failing there?