<aura:component implements="lightning:isUrlAddressable" access="global" >
<!-- handlers-->
<aura:handler name="init" value="{! this }" action="{! c.init }"/>
<!-- Main attribute uses to display all of the group structures as PDF -->
<aura:attribute name="groupstructures" type="Group_Structure__c[]"/>
<aura:attribute name="columns" type="List"/>
<!--Attributes for Sorting table -->
<aura:attribute name="sortedBy"
type="String" />
<aura:attribute name="sortedDirection"
type="Boolean"
default="true"
/>
<!-- Button to print PDF -->
<ui:button label="Print" press="{!c.PrintTable}"/>
<!-- the container element determine the height of the datatable -->
<div style="height: 300px">
<lightning:datatable aura:id="gstable"
data="{! v.groupstructures }"
columns="{! v.columns }"
sortedBy="{!v.sortedBy}"
sortedDirection="{!v.sortedDirection}"
onsort="{!c.updateColumnSorting}"
hideCheckboxColumn="true" />
</div>
</aura:component>
Here is my controller:
({
init: function (cmp, event, helper) {
//set the groupstructures attribute that is being passed via page reference need the next two lines of code
var pageReference = cmp.get("v.pageReference");
cmp.set("v.groupstructures", pageReference.state.groupstructures);
cmp.set('v.columns', [
{label: 'Status', fieldName: 'Status__c', type: 'text', sortable: true},
{label: 'Funding Type', fieldName: 'Funding_Type__c', type: 'text', sortable: true},
{label: 'Group Number', fieldName: 'Group_Number__c', type: 'text', sortable: true},
{label: 'Section Code', fieldName: 'Section_Code__c', type: 'text', sortable: true},
{label: 'Package Code', fieldName: 'Package_Code__c', type: 'text', sortable: true},
{label: 'Effectve Date', fieldName: 'Effective_Date__c', type: 'text', sortable: true},
{label: 'End Date', fieldName: 'End_Date__c', type: 'text', sortable: true},
{label: 'Health_Product', fieldName: 'Health_Product__c', type: 'text', sortable: true},
{label: 'Prescription?', fieldName: 'Prescription__c', type: 'text', sortable: true},
{label: 'Dental?', fieldName: 'Dental__c', type: 'text', sortable: true},
{label: 'Vision?', fieldName: 'Vision__c', type: 'text', sortable: true},
{label: 'CDH Status', fieldName: 'CDH_Status__c', type: 'text', sortable: true},
{label: 'Coverage Categories', fieldName: 'Coverage_Categories__c', type: 'text'},
{label: 'Prefix', fieldName: 'Prefix__c', type: 'text', sortable: true},
{label: 'Description', fieldName: 'Description__c', type: 'text', sortable: true}
]);
console.log("⌗⌗⌗ here is the groupstructures ???" + JSON.stringify(cmp.get("v.groupstructures")));
},
updateColumnSorting: function(component, event, helper) {
var fieldName = event.getParam('fieldName');
var sortDirection = event.getParam('sortDirection');
// assign the latest attribute with the sorted column fieldName and sorted direction
component.set("v.sortedBy", event.getParam("fieldName"));
component.set("v.sortedDirection", event.getParam("sortDirection"));
helper.sortData(component, fieldName, sortDirection);
},
PrintTable : function(component, event, helper) {
var url = location.origin + '/apex/GroupStructureListPrint'
;
window.open(url, '_self');
console.log("⌗⌗⌗ Im in the PrintPageAction");
},
})
Any help would be greatly appreciated!!! thanks!!
FredUnfortunately, that did not work. I think it has something to do with the attribute. I'm seeing the column headings but not the data. thanks!