views:

1196

answers:

4

Deletion operations seems to be the slowest in a YUI datatable. I have a datatable with > 300 rows. I need to delete selected rows. I tried removing the selected records from the recordset and then calling table.render() .. While this is okay, can it be made better?

+2  A: 

Have a look at the API docs on the "deleteRow" method for the datatable widget (at http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable.html#method_deleteRow). This looks to me like this is what you'd want. Perhaps something like:

var selected = theDataTable.getSelectedRows();
var rset = theDataTable.getRecordSet();

for (var x = 0; x < selected.length; x++) {
    theDataTable.deleteRow(rset.getRecordIndex(rset.getRecord(selected[x]))
}
Evan Anderson
A: 

No. This is slower than what I wrote. Here you delete row by row and each time datatable has to be re-rendered.

What I did was remove these records from he recordset and then render the datable once. Thats faster, but not a whole lot.

A: 

To my knowledge that is the fastest way to delete a row from a yui datatable. However, for your user's sake, unless 300 rows is necessary, you should consider pagination which is improved in version 2.6.0 (and has been split out and can now be used on other objects and not just DataTable).

Anthony Potts
A: 

Thanks Anthony..Pagination scales well.