AnsweredAssumed Answered

How do I select multiple rows from my dGrid?

Question asked by schlot on Sep 2, 2014
Latest reply on Sep 4, 2014 by schlot

I'm having a hard time managing my selected rows in my dGrid.  I read that the default selection mode is already set to extended. I have an event on dgrid-select that fire my chart function and that works.  I'd to be able to select mutiple rows from the grid to generate a chart with the information from multiple rows, but I'm having a hard time managing the selection.  As soon as I select one row, my chart gets generated.

 

I am creating my grid based on a featureLayer,queryFeatures.  Here's the result handler.

function gridHandler(results) {
  var rateTest, countTest;
  var returnObj = {};
  domConstruct.empty(dom.byId('gridDiv'));
    var gridColumns = buildColumns();

    var data = arrayUtils.map(results.featureSet.features, function(feature){     
      return feature.attributes;
   });

  grid = new (declare([Grid, Selection]))({
        id:'grid', 
        columns: gridColumns
        }, "gridDiv"); 
       grid.renderArray(data);
       grid.sort('County');  

     grid.on("dgrid-select", function(event){
        var rows = event.rows;
        var row = event.rows[0];
        var gridQuery = new Query();                                          
        gridQuery.objectIds = [row.data.OBJECTID];
        featureLayer.selectFeatures(gridQuery, FeatureLayer.SELECTION_NEW, function(results) {
          if ( results.length > 0 ) {
           // createLineChart(results);
           createLineChart(results[0]);
            var feature = results[0];
            feature.setInfoTemplate(infoTemplate);
            var resultGeometry = results[0].geometry; 
            map.infoWindow.setFeatures(results);
      //    map.infoWindow.show(resultGeometry.getExtent().getCenter());      //assume geometry is a polygon      
          } else {
            console.log("error in grid.on click function");
          }
        }); 
        });  
    dom.byId("gridText").innerHTML = title+ " - " + currentYear;
}
//creates a column definition for the grid based on the attributes returned from the query
  function buildColumns() {
       var columns = [];
 //qryOutFields is an array of fieldNames defined earlier
    arrayUtils.forEach(qryOutFields, function(field){
            var objects = {};
            objects.label = field;
            objects.field = field;
            if (field === 'OBJECTID') {//assumed name for internal ID from map service
                objects.hidden = true;
            }
            columns.push(objects);
        });
        
    return columns;
}

Outcomes