Skip to content

Commit

Permalink
MDL-36548: Major performance boost to Detail (list) view in file picker
Browse files Browse the repository at this point in the history
Pass the data (filelist) into the DataTable when initialising it, rather than rendering an empty DataTable and then pushing all of the data into it via addRows().

It's also slightly more efficient to just pass the node in, rather than fetching the node and passing its ID in, as DataTable.render() will just re-select the node if given the ID. [Spotted by Andrew Nicols]
  • Loading branch information
pauln committed Nov 13, 2012
1 parent ff63a3a commit 04fa1da
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions repository/filepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ YUI.add('moodle-core_filepicker', function(Y) {
}
/** initialize table view */
var initialize_table_view = function() {
var parentid = scope.one('.'+classname).get('id');
var cols = [
{key: "displayname", label: M.str.moodle.name, allowHTML: true, formatter: formatTitle,
sortable: true, sortFn: sortFoldersFirst},
Expand All @@ -332,8 +331,13 @@ YUI.add('moodle-core_filepicker', function(Y) {
{key: "mimetype", label: M.str.repository.type, allowHTML: true,
sortable: true, sortFn: sortFoldersFirst}
];
scope.tableview = new Y.DataTable({columns: cols});
scope.tableview.render('#'+parentid);
for (var k in fileslist) {
// to speed up sorting and formatting
fileslist[k].displayname = file_get_displayname(fileslist[k]);
fileslist[k].isfolder = file_is_folder(fileslist[k]);
fileslist[k].classname = options.classnamecallback(fileslist[k]);
}
scope.tableview = new Y.DataTable({columns: cols, data: fileslist});
scope.tableview.delegate('click', function (e, tableview) {
var record = tableview.getRecord(e.currentTarget.get('id'));
if (record) {
Expand All @@ -353,13 +357,8 @@ YUI.add('moodle-core_filepicker', function(Y) {
}
/** append items in table view mode */
var append_files_table = function() {
for (var k in fileslist) {
// to speed up sorting and formatting
fileslist[k].displayname = file_get_displayname(fileslist[k]);
fileslist[k].isfolder = file_is_folder(fileslist[k]);
fileslist[k].classname = options.classnamecallback(fileslist[k]);
}
scope.tableview.addRows(fileslist);
var parentnode = scope.one('.'+classname);
scope.tableview.render(parentnode);
scope.tableview.sortable = options.sortable ? true : false;
};
/** append items in tree view mode */
Expand Down

0 comments on commit 04fa1da

Please sign in to comment.