Skip to content

Instantly share code, notes, and snippets.

@choudharymanish8585
Last active June 28, 2018 10:01
Show Gist options
  • Save choudharymanish8585/473d9fe8ea07b8605aafa9d153265506 to your computer and use it in GitHub Desktop.
Save choudharymanish8585/473d9fe8ea07b8605aafa9d153265506 to your computer and use it in GitHub Desktop.
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes"
access="global"
controller="AccountController">
<aura:attribute name="data" type="Object"/>
<aura:attribute name="columns" type="List"/>
<aura:attribute name="recordId" type="String"/>
<aura:attribute name="pageNumber" type="Integer" default="1"/>
<aura:attribute name="pageSize" type="Integer" default="10"/>
<aura:attribute name="isLastPage" type="Boolean" default="false"/>
<aura:attribute name="resultSize" type="Integer" default="0"/>
<!-- This attribute will hold the update records from data table-->
<aura:attribute name="updatedRecord" type="Object[]" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<!-- You must define keyField as 'Id' to save the record back in Salesforce
'onsave' attribute will executed when user clicks on save button -->
<lightning:card title="Datatable With Pagination">
<lightning:layout multipleRows="true" horizontalAlign="center">
<lightning:layoutItem padding="around-small" size="12">
<lightning:datatable
aura:id="accountDataTable"
columns="{! v.columns }"
data="{! v.data }"
keyField="Id"
hideCheckboxColumn="true" />
</lightning:layoutItem>
<lightning:layoutItem padding="around-small" flexibility="auto">
<lightning:button label="Prev" iconName="utility:chevronleft" iconPosition="left"
onclick="{!c.onPrev}" disabled="{! v.pageNumber == 1}"/>
<span class="slds-p-horizontal_small">
Page {!v.pageNumber} | Showing records from {! ((v.pageNumber-1)*v.pageSize)+' to '+((v.pageNumber-1)*v.pageSize+v.resultSize)}
</span>
<lightning:button label="Next" iconName="utility:chevronright" iconPosition="right"
disabled="{! v.isLastPage}" onclick="{!c.onNext}"/>
</lightning:layoutItem>
</lightning:layout>
</lightning:card>
</aura:component>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment