项目作者: Manzanit0
项目描述 :
A reusable button packaged as a lightning component to export JS objects as a CSV
高级语言: JavaScript
项目地址: git://github.com/Manzanit0/CsvExporterButton.git
Use
<aura:component description="ExampleComponent" controller="ExampleController">
<!--
- In your code, implement an Apex Controller which retrieves some records,
- as well as the init action to populate the table.
-->
<!-- attributes -->
<aura:attribute type="Object[]" name="allRecords" ></aura:attribute>
<aura:attribute type="List" name="columns" ></aura:attribute>
<!-- handlers-->
<aura:handler name="init" value="{! this }" action="{! c.init }"></aura:handler>
<aura:handler name="change" value="{!v.allRecords}" action="{!c.renderPage}" ></aura:handler>
<lightning:card title="Example">
<aura:set attribute="actions">
<!-- Simply give the button the records and the export file name -->
<c:CsvExporterButton records="{!v.allRecords}" fileName="export.csv" ></c:CsvExporterButton>
</aura:set>
<p class="slds-p-horizontal_small">
<lightning:datatable
keyField="id"
data="{! v.allRecords }"
columns="{! v.columns }"
hideCheckboxColumn="true"></lightning:datatable>
</p>
</lightning:card>
</aura:component>