You need to sign in to do that
Don't have an account?

Setting Attribute using pageReference State
I am opening a second component and passing an attribute using the pageReference.state. I can see the attribute is populated when I do a console.log. However, the following lightning:datatable is not displaying any of the groupstructure attributes values. Here is my component:
Fred
<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!!
Fred
Try to set the value to the table after initiating the columns in the init method
//first comp.set(v.columns, ''[])
//next cmp.set("v.groupstructures", pageReference.state.groupstructures);
share the results. we will see more in case if that doesn't work.
Naveen