AnsweredAssumed Answered

Is there any method to change report class api?

Question asked by zhouleizhou on Aug 10, 2017
Latest reply on Aug 14, 2017 by zhouleizhou

ESRI released its new report widget using report class, I am trying to let the report widget print my query result, which is sent from another query widget. 

 

The data is sent from another widget uisng publishData function as an object, it is census data such as census tracts. The sending object has been tested: it is an array object containing 23 row records and each one has 57 fields as columns, e.g., 23 census tracts and each one contains fields like ID, Name, Area, Population ...

 

My codes inserting to the report widget is like the following, the colItem and rowItem are defined at the beginning of the report widget as colItem:null, rowItem:null,
queryResult is defined in publishData() in another widget to pass the query result as 

 

this.publishData({
'target': 'Report',
'queryResult': this.results
});

 

My question is how to make the queryResult to display in Report widget in a good format? At least displaying as a table with fields as columns and census tracts as row records. Thanks a lot!

 

onReceiveData: function(name, widgetId, data, historyData) {
   
       if(widgetId === 'widgets_test_36') {
        console.log("Report widget got the message"); 
       
       var resultItems = [];
       var resultCount = data.queryResult.length;
       for (var i =0; i<data.queryResult.length; i++) {
            var featureAttributes = data.queryResult[i].attributes; //each row record
           //The next is to handle fields of each record and push them into resultItems
            for (var attr in featureAttributes){
                 resultItems.push(featureAttributes[attr]);
            }
            this.rowItem = resultItems;
            console.info(this.rowItem);
        }  
     }
    }
   
    _onBtnPrintClicked: function(){
          var printData = [
          {
            addPageBreak: true,
            type: "map",
            map: this.map
          },
       
        {
            title: "Testing Report",
            addPageBreak: false,
            type: "table",
            tableCols: 4,
            data: {
               showRowIndex: true,
               cols: this.colItem,// I have no idea how to code this?
               rows: this.rowItem
            }
          }  
  ];
 
        this.report.print("Testing Report", printData);
      }, //_onBtnPrintClicked funciton ends

Outcomes