I am developing a lightning component. In this component there is an attribute called allItems
that contains an array of objects. Currently tested holding up to 600 objects.
However when I call a component.set
with an updated array of objects, it takes a while to set/save the attribute and update the page visually.
Is there any way to improve speed/performance of component.set
?
Code:
onItemMoved: function(component, event, helper)
{
var titleid = event.getParam("titleid");
var title = event.getParam("title");
var maxSeats = event.getParam("maxSeats");
var seatsInUse = event.getParam("seatsInUse");
var item = event.getParam("item"); //This is the item that was moved.
var allGuestsList = component.get("v.allItems");
console.log(item.index);
//Searches guest list for matching guest. .
//var actualGuest = allGuestsList.find(function(moving){return moving.id == item.id;});
//Has the guest been moved to another table?
if(item.status != title)
{
//Does table have seats spare?
if(seatsInUse>=maxSeats)
{
console.log(title, 'is full!\nMaximum guests for this table:', maxSeats);
}
else
{
item.status = title;
item.statusid = titleid;
allGuestsList[item.index] = item;
component.set("v.allItems", allGuestsList);//This Line has slow performance past 200 objects being loaded.
}
}
})
Best Answer
How did you conclude that
component.set()
is the culprit? Also, are you viewing all 600 records in one-go on a page? If so, I have a feeling that this is more of a display issue than an issue withcomponent.set()
itself. You can determine that by measuring the time taken forcomponent.set()
to execute like so:If the time reported is reasonably small, you know what I am talking about. It could be the actual time taken to render so much data on the page. To prove/test it, there are a few things you could try:
v.allItems
, but only render a few lines as opposed to ALL using anaura:if
or something similar in your markup.<td>{!item.Name}</td>
as opposed tolightning:*
orui:*
base components like<td><lightning:formattedText value="{!item.Name}"/></td>
and see if the performance improves. If it does, you might have to consider implementing pagination.