RParadox
RParadox

Reputation: 6881

YUI datatable performance

In YUI3 (3.11) adding 100 items to my table takes 800ms. What are some ways to optimize this (and why is this so slow in the first place)?

data = data.slice(1,100)
data.forEach(function(item){
   data_table.data.add({ 'name': item });
})

Upvotes: 2

Views: 171

Answers (1)

Clarence Leung
Clarence Leung

Reputation: 2566

DataTable.data uses a YUI ModelList internally to store data, which turns all of your rows into Models and fires an add event when you add them to your table. It's currently not meant to have many rows added to it at once, though, because of that.

The best way of solving your problem is probably to reset the table with only the rows that you want to show. You can do that by doing:

data = data.slice(1, 100);
data_table.data.reset(data);

That will let you add data to your DataTable with a lot less overhead, and prevent the firing of those additional events.

Upvotes: 1

Related Questions