I am new to Lightning, and I would like to create a table that I could set (by a picklist) the number of rows that will appear. I have tried to put the number of rows by default, setting on the attribute indexVar the number of the rows, but there is no effect (it is showing all values). This is the code of the table.
<aura:attribute name="indx" type="Integer" default="5" />
<aura:iteration items="{!v.adressList}" var="dir" indexVar="{!v.indx}">
<tr>
<td><div class="slds-truncate" title="{!dir.FE_sales_Country__c}">
{!dir.FE_sales_Country__c}</div></td>
<td><div class="slds-truncate" title="{!dir.FE_Sales_City__c}">
{!dir.FE_Sales_City__c}</div></td>
<td><a href="{!'/one/one.app?#/sObject/'+ dir.Street__c + '/view'}"
target="_blank">{!dir.Street__r.Name}</a></td>
</tr>
</aura:iteration>
The code of the picklist is the next one (I still have to do doAction
to set the value of the rows, I guess that I should just set the value to the indx
attribute):
<lightning:select name="mySelect" label="Select an option:" aura:id="mySelect" value="{!v.rowValue}" onchange="{!c.doAction}">
<aura:iteration items="{!v.rowoptions}" var="item" >
<option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/>
</aura:iteration>
</lightning:select>
And in the controller I have put this code:
loadRowOptions: function (component, event, helper) {
var opts = [
{ value: "5", label: "5" },
{ value: "10", label: "10" },
{ value: "25", label: "25" },
{ value: "50", label: "50" }
];
component.set("v.rowoptions", opts);
}
So I think the main problem is that I am not able to just show the number of rows that I want.
indexVar
attribute works. In fact, this is an output attribute. You can't have control on it. The iteration will loop through your collection and you'll be able to know the current index using theindexVar
attribute.