Skip to content

Commit 20c41eb

Browse files
committed
Grid Editing: Update template usage for better performance and less code
1 parent 6d1fe3d commit 20c41eb

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

grid-spf/grid.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,9 @@ $.widget( "ui.grid", {
3232
},
3333
refresh: function() {
3434
// TODO this code assumes a single tbody which is not a safe assumption
35-
var tbody = this.element.find( "tbody" ).empty(),
36-
template = this.options.rowTemplate;
37-
// TODO try to replace $.each with passing an array to $.tmpl, produced by this.items.something()
38-
// TODO how to refresh a single row?
39-
$.each( this.options.source.toArray(), function( itemId, item ) {
40-
// TODO use item.toJSON() or a method like that to compute values to pass to tmpl
41-
$.tmpl( template, item ).appendTo( tbody );
42-
});
35+
var tbody = this.element.find( "tbody" ).empty();
36+
// TODO how to refresh a single row? -> tmplItem().update()
37+
$.tmpl( this.options.rowTemplate, this.options.source.toArray() ).appendTo( tbody );
4338
tbody.find( "td" ).addClass( "ui-widget-content" );
4439
this._trigger("refresh");
4540
},
@@ -82,7 +77,8 @@ $.widget( "ui.grid", {
8277
return "<td>${" + field + "}</td>";
8378
}).join( "" );
8479
template = "<tr>" + template + "</tr>";
85-
this.options.rowTemplate = template;
80+
// compile the template
81+
this.options.rowTemplate = $.template( template );
8682
}
8783
});
8884

0 commit comments

Comments
 (0)