Faster YUI DataTable with 5 Lines of Code

Holy Reflows Batman! The typical usage of a DataTable in the Yahoo User Interface JavaScript library involves passing a string into the constructor signifying the ID attribute of the container you want to attach the DataTable to. However, the YUI D…


This content originally appeared on Zach Leatherman and was authored by Zach Leatherman

Holy Reflows Batman! The typical usage of a DataTable in the Yahoo User Interface JavaScript library involves passing a string into the constructor signifying the ID attribute of the container you want to attach the DataTable to. However, the YUI DataTable loves the DOM and creating nodes individually using DOM methods. Normally that’d be fine, but one of the first things it does in the constructor is create the table element and attach it to the live DOM. This is a no-no. Now, every time they append a new node (for a new row or a new cell inside of a row), it causes a reflow in the browser! What does this mean? Really bad lag when you insert 40 or 50 rows. Recognize this piece of code?

var myDataTable = new YAHOO.widget.DataTable("myContainer", myColumnDefs, myDataSource);

Straight from the docs. No no no!

Instead, you should pass in an unattached DOM node instead of a string!

Try this code on for size:

var myDataTable = new YAHOO.widget.DataTable(document.createElement('div'), myColumnDefs, myDataSource); 
myDataTable.subscribe('initEvent',function() {
    // CHANGE THIS -- match the id of the container you want.
    var d = document.getElementById('myContainer');
    // remove previous DataTables
    while(d.firstChild) { d.removeChild(d.firstChild); };
    d.appendChild(this._elContainer); });
}


This content originally appeared on Zach Leatherman and was authored by Zach Leatherman


Print Share Comment Cite Upload Translate Updates
APA

Zach Leatherman | Sciencx (2007-12-27T06:00:00+00:00) Faster YUI DataTable with 5 Lines of Code. Retrieved from https://www.scien.cx/2007/12/27/faster-yui-datatable-with-5-lines-of-code/

MLA
" » Faster YUI DataTable with 5 Lines of Code." Zach Leatherman | Sciencx - Thursday December 27, 2007, https://www.scien.cx/2007/12/27/faster-yui-datatable-with-5-lines-of-code/
HARVARD
Zach Leatherman | Sciencx Thursday December 27, 2007 » Faster YUI DataTable with 5 Lines of Code., viewed ,<https://www.scien.cx/2007/12/27/faster-yui-datatable-with-5-lines-of-code/>
VANCOUVER
Zach Leatherman | Sciencx - » Faster YUI DataTable with 5 Lines of Code. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2007/12/27/faster-yui-datatable-with-5-lines-of-code/
CHICAGO
" » Faster YUI DataTable with 5 Lines of Code." Zach Leatherman | Sciencx - Accessed . https://www.scien.cx/2007/12/27/faster-yui-datatable-with-5-lines-of-code/
IEEE
" » Faster YUI DataTable with 5 Lines of Code." Zach Leatherman | Sciencx [Online]. Available: https://www.scien.cx/2007/12/27/faster-yui-datatable-with-5-lines-of-code/. [Accessed: ]
rf:citation
» Faster YUI DataTable with 5 Lines of Code | Zach Leatherman | Sciencx | https://www.scien.cx/2007/12/27/faster-yui-datatable-with-5-lines-of-code/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.