//Main Component
<aura:component controller="LightningReportsController" implements="force:appHostable">
<!-- Dynamically load the report rows -->
<aura:attribute name="reportResponse" type="Object"/>
<table >
<thead>
<c:reportRowComponent row="{!v.reportResponse.reportFields}" isHeader="true"/>
</thead>
<tbody>
<aura:iteration var="row" items="{!v.reportResponse.fieldDataList}">
<C:reportRowComponent row="{!row}" isHeader="false"/>
</aura:iteration>
</tbody>
</table>
</aura:component>
---------------------------------------------------------
//Aura Component Controller
var action = component.get("c.getReportResponse");
action.setParams({
"Param1" : parmValue1,
"Param2":parmValue2
});
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS")
{
var reportResponseObj = JSON.parse(response.getReturnValue());
component.set("v.reportResponse", reportResponseObj);
}
});
$A.enqueueAction(action);
------------------------------------------------------------
//reportRowComponent
<aura:component implements="force:appHostable">
<aura:attribute name="row" type="Object[]"/>
<aura:attribute name="isHeader" type="Boolean"/>
<tr>
<aura:iteration var="cell" items="{!v.row}">
<aura:renderIf isTrue="{!v.isHeader}">
<th >{!cell.fieldLabel}</th>
<aura:set attribute="else">
<td>
<aura:renderIf isTrue="{!cell.isHyperLink}">
<c:sobjectHyperlink sObjectId="{!cell.fieldValue}" hyperlinkLabel="{!cell.fieldLabel}"/>
<aura:set attribute="else">{!cell.fieldLabel}</aura:set>
</aura:renderIf>
</td>
</aura:set>
</aura:renderIf>
</aura:iteration>
</tr>
</aura:component>
------------------------------------------------------------
public class LightningReportsController
{
@AuraEnabled
public static String getReportResponse(String Parm1,String Parm2) {
return JSON.serialize(ReportClass.getTabularReportResponse('00O2REPORTIDXXX',Parm1,Parm2));
}
}
------------------------------------------------------------
public class ReportClass
{
public class tabularReportResponse{
public List<fieldDef > reportFields {get; set;}
public List<List<fieldData>> fieldDataList {get; set;}
public tabularReportResponse(){}
}
public class fieldDef {
public String fieldName {get; set;}
public String fieldLabel {get; set;}
public String dataType {get; set;}
public fieldDef(){}
}
public class fieldData {
public String fieldValue {get; set;}
public String fieldLabel {get; set;}
public String dataType {get; set;}
public Boolean isHyperLink {get; set;}
public fieldData(){isHyperLink=false;}
}
public Static tabularReportResponse getTabularReportResponse(Id reportId,String Param1,String Param2) {
tabularReportResponse trr = new tabularReportResponse();
List<fieldDef> reportFields = new List<fieldDef>();
List<List<fieldData>> fieldDataList = new List<List<fieldData>>();
Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(reportId);
Reports.ReportMetadata reportMd = describe.getReportMetadata();
// Override filter and run report
Reports.ReportFilter filter = reportMd.getReportFilters()[0];
filter.setValue(Param1);
Reports.ReportFilter filter2 = reportMd.getReportFilters()[1];
filter2.setValue(Param2);
Reports.ReportResults results = Reports.ReportManager.runReport(reportId, reportMd,true);
//get the report result
// Reports.ReportResults results = Reports.ReportManager.runReport(reportId, true);
//get the metadata
Reports.ReportMetadata reportMetadata = results.getReportMetadata();
//get a string array of the field names
List<String> fieldNames = reportMetadata.getDetailColumns();
//get the extended metadata
Reports.ReportExtendedMetadata reportExtendedMetadata = results.getReportExtendedMetadata();
//get the map of the column names to their name and label
Map<String, Reports.DetailColumn> detailColumnMap = reportExtendedMetadata.getDetailColumnInfo();
//loop over the detailColumnMap and get the name, label, and data type
for (String fieldName: fieldNames) {
Reports.DetailColumn detailColumn = detailColumnMap.get(fieldName);
fieldDef fd = new fieldDef();
fd.fieldName = detailColumn.getName();
fd.fieldLabel = detailColumn.getLabel();
fd.dataType = detailColumn.getDataType().name();
reportFields.add(fd);
}
// Get the fact map from the report results
Reports.ReportFactWithDetails factDetails = (Reports.ReportFactWithDetails)results.getFactMap().get('T!T');
List<reports.ReportDetailRow> reportDetailRowList = factDetails.getRows();
//loop over the rows
for (Reports.ReportDetailRow reportDetailRow: reportDetailRowList) {
Integer cellCounter = 0;
List<fieldData> fieldDataRow = new List<fieldData>();
//loop over the cells in the row
for (Reports.ReportDataCell reportDataCell: reportDetailRow.getDataCells()) {
fieldData fd = new fieldData();
fd.fieldValue = String.valueof(reportDataCell.getValue());
fd.fieldLabel = String.valueOf(reportDataCell.getLabel());
fd.dataType = reportFields[cellCounter].dataType;
cellCounter++;
fieldDataRow.add(fd);
}
fieldDataList.add(fieldDataRow);
}
trr.reportFields = reportFields;
trr.fieldDataList = fieldDataList;
return trr;
}
}