dgrid/Grid not displaying values

867
3
Jump to solution
04-10-2017 02:58 AM
SibghatUllah1
Occasional Contributor

I am running a query to get count of features on two layers and show it in a dgrid . Dgrid is  only hsowing the headings and nothing else .I have run the code using alert() and get the counts of both layers. I think the problem is in array.Please guide.

on(dom.byId("search1"), "click", function () {

var typesData = [];

for(var j=15;j<17;j++){

var queryTask3 = new esri.tasks.QueryTask("http://localhost:6080/arcgis/rest/services/RAEC/MapServer/"+j);

var query3 = new esri.tasks.Query();

query.outFields = ["OBJECTID"];

query3.returnGeometry = false;

query3.where = "FeederID='HITAM POW F2'";

queryTask3.executeForCount(query3,function (count) {

//alert(count);

var b={ field: j, field1: count };

typesData.push(b);

});

}

var grid= new Grid({   

     columns: {

field: 'Layers', field1: 'Count' }

}, 'grid');

grid.renderArray(typesData); });

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Regular Contributor

The QueryTask returns a deferred object. You need to wait till all the deferred are resolved, by using "dojo/promise/all"

on(dom.byId("search1"), "click", function () {
     var typesData = [];
     var allPromises = [];
     for(var j=15;j<17;j++){
          var queryTask3 = new QueryTask("http://localhost:6080/arcgis/rest/services/RAEC/MapServer/"+j);
          var query3 = new Query();
          query.outFields = ["OBJECTID"];
          query3.returnGeometry = false;
          query3.where = "FeederID='HITAM POW F2'";
          var promise = queryTask3.executeForCount(query3,function (count) {
               //alert(count);
               var b={ field: j, field1: count };
               typesData.push(b);
          });
          allPromises.push(promise);
     }
     all(allPromises).then(function(){
          var grid= new Grid({   
               columns: {
               field: 'Layers', field1: 'Count' }
          }, 'grid');
          grid.renderArray(typesData);
     });
});

Also, I find that you are mixing AMD and legacy styles, that is not a good practice. I have fixed that for you (Query and Query Task).

View solution in original post

3 Replies
thejuskambi
Regular Contributor

The QueryTask returns a deferred object. You need to wait till all the deferred are resolved, by using "dojo/promise/all"

on(dom.byId("search1"), "click", function () {
     var typesData = [];
     var allPromises = [];
     for(var j=15;j<17;j++){
          var queryTask3 = new QueryTask("http://localhost:6080/arcgis/rest/services/RAEC/MapServer/"+j);
          var query3 = new Query();
          query.outFields = ["OBJECTID"];
          query3.returnGeometry = false;
          query3.where = "FeederID='HITAM POW F2'";
          var promise = queryTask3.executeForCount(query3,function (count) {
               //alert(count);
               var b={ field: j, field1: count };
               typesData.push(b);
          });
          allPromises.push(promise);
     }
     all(allPromises).then(function(){
          var grid= new Grid({   
               columns: {
               field: 'Layers', field1: 'Count' }
          }, 'grid');
          grid.renderArray(typesData);
     });
});

Also, I find that you are mixing AMD and legacy styles, that is not a good practice. I have fixed that for you (Query and Query Task).

SibghatUllah1
Occasional Contributor

thejus kambi

Thank you very much.It worked, I was missing dojo/promise/all. And thanks for correcting the code to AMD.

0 Kudos
thejuskambi
Regular Contributor

No problem, Don't forget to mark the question as answered.

0 Kudos