Need to listen for data load before setting renderRow on dgrid

3115
0
06-04-2015 10:18 AM
TracySchloss
Frequent Contributor

I have a rather complex query that I'm running and the results need to go into a dGrid which is formatted with a renderRow.  I have successfully used this in the past.  I think it might be the size of my data set, because I'm getting an error in my renderRow function that the object I should be passing isn't yet available. 

Sometimes this works.  Otherwise, if I put a breakpoint in my renderRowFunction, this gives the process enough time to format my data and then it works.

var dataGrid = new declare([Grid, Selection]);

       datagrid = new dataGrid({
        showHeader: false,
          renderRow:renderRowFunction
        }, "gridDiv");
        
            function renderRowFunction(obj, options){
                var template = '<div class="gridTitle gridInfo">${0}</div><div class="details gridInfo">${1}</div> <div class="details gridInfo">${2}</div><div class="details gridInfo"> ${3}, ${4}</div><div class="details gridInfo">${5}</div><div class="details gridInfo provider">Provider Type: ${6}</div><div class="details gridInfo provider">Specialty: ${7}</div>';
                var divString = String.substitute(template, [obj.facility, obj.address,obj.address2, obj.city,obj.state,obj.phone,obj.provider,obj.specialty])
                var div = domConstruct.create("div", {
                    innerHTML: divString
                });
                return div;
            }

The grid is populated from  featureLayer, which  has a definition expression on it.  Since that filter is in place, I only need to a simple where clause to get all the elements to populate the grid.  I also have an extent-change listeners to limit the contents to the current map extent.

 function updateGrid(){
       var query = new Query();
       query.where = '1=1';
       query.geometry = currentExtent;
       featureLayer.on("selection-complete", featureLayerQueryHandler, errorHandler);
       featureLayer.selectFeatures(query);
     }
     
      function featureLayerQueryHandler(response){
        var data = [];
          data = arrayUtils.map(response.features, function(feature){
              return {
                  'id': feature.attributes.ESRI_OID,
                  'facility': feature.attributes.NA_PROVIDER,
                  'address': feature.attributes.AD_LINE1,
                  'address2':feature.attributes.AD_LINE2,
                  'city': feature.attributes.AD_CITY,
                  'state': feature.attributes.AD_STATE,
                  'phone':phoneFormatter(feature.attributes.PH_NUMBER),
                  'provider':findProvCode(feature.attributes.ID_PROV_TYPE_FK),
                  'specialty':findSpecCode(feature.attributes.ID_SPECIALTY_FK)
              };
          });
            var currentMemory = new Memory({
                data: data,
                idProperty: 'id'
            });
          datagrid.set('store', currentMemory);
          datagrid.sort('facility');

      }

Could I set something up to only define the renderRow after datagrid is populated?

0 Kudos
0 Replies