Permalink
Browse files

Made DataView filter inlining optional (default is false).

  • Loading branch information...
1 parent c9c9f3a commit c95128f8b3586c74773221f8b5531c60bc63339b @mleibman committed Feb 5, 2012
@@ -222,7 +222,8 @@
var groupItemMetadataProvider = new Slick.Data.GroupItemMetadataProvider();
dataView = new Slick.Data.DataView({
- groupItemMetadataProvider: groupItemMetadataProvider
+ groupItemMetadataProvider: groupItemMetadataProvider,
+ inlineFilters: true
});
grid = new Slick.Grid("#myGrid", dataView, columns, options);
@@ -121,7 +121,7 @@
data[i] = new DataItem(i);
}
- dataView = new Slick.Data.DataView();
+ dataView = new Slick.Data.DataView({ inlineFilters: true });
grid = new Slick.Grid("#myGrid", dataView, columns, options);
var pager = new Slick.Controls.Pager(dataView, grid, $("#pager"));
@@ -194,7 +194,7 @@
}
- dataView = new Slick.Data.DataView();
+ dataView = new Slick.Data.DataView({ inlineFilters: true });
grid = new Slick.Grid("#myGrid", dataView, columns, options);
grid.setSelectionModel(new Slick.RowSelectionModel());
@@ -182,7 +182,7 @@
// initialize the model
- dataView = new Slick.Data.DataView();
+ dataView = new Slick.Data.DataView({ inlineFilters: true });
dataView.beginUpdate();
dataView.setItems(data);
dataView.setFilter(myFilter);
View
@@ -23,7 +23,8 @@
var self = this;
var defaults = {
- groupItemMetadataProvider: null
+ groupItemMetadataProvider: null,
+ inlineFilters: false
};
@@ -526,14 +527,45 @@
return fn;
}
+ function uncompiledFilter(items, args) {
+ var retval = [], idx = 0;
+
+ for (var i = 0, ii = items.length; i < ii; i++) {
+ if (filter(items[i], args)) {
+ retval[idx++] = items[i];
+ }
+ }
+
+ return retval;
+ }
+
+ function uncompiledFilterWithCaching(items, args, cache) {
+ var retval = [], idx = 0, item;
+
+ for (var i = 0, ii = items.length; i < ii; i++) {
+ item = items[i];
+ if (cache[i]) {
+ retval[idx++] = item;
+ } else if (filter(item, args)) {
+ retval[idx++] = item;
+ cache[i] = true;
+ }
+ }
+
+ return retval;
+ }
+
function getFilteredAndPagedItems(items) {
if (filter) {
+ var batchFilter = options.inlineFilters ? compiledFilter : uncompiledFilter;
+ var batchFilterWithCaching = options.inlineFilters ? compiledFilterWithCaching : uncompiledFilterWithCaching;
+
if (refreshHints.isFilterNarrowing) {
- filteredItems = compiledFilter(filteredItems, filterArgs);
+ filteredItems = batchFilter(filteredItems, filterArgs);
} else if (refreshHints.isFilterExpanding) {
- filteredItems = compiledFilterWithCaching(items, filterArgs, filterCache);
+ filteredItems = batchFilterWithCaching(items, filterArgs, filterCache);
} else if (!refreshHints.isFilterUnchanged) {
- filteredItems = compiledFilter(items, filterArgs);
+ filteredItems = batchFilter(items, filterArgs);
}
} else {
// special case: if not filtering and not paging, the resulting
@@ -36,7 +36,7 @@
d["duration"] = Math.round(Math.random() * 14);
}
- var dv = new Slick.Data.DataView();
+ var dv = new Slick.Data.DataView({inlineFilters: true});
dv.beginUpdate();
dv.setItems(data);
dv.setFilter(filter);

0 comments on commit c95128f

Please sign in to comment.