Skip to content

Instantly share code, notes, and snippets.

@zedar
Last active August 29, 2015 14:02
Show Gist options
  • Save zedar/2cce66bc82814c887ea8 to your computer and use it in GitHub Desktop.
Save zedar/2cce66bc82814c887ea8 to your computer and use it in GitHub Desktop.
dojo FilteringSelect with cached entries
declare([
"dojo/_base/declare",
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dijit/form/FilteringSelect"
], function(declare, JsonRest, Memory, Cache, FilteringSelect) {
var _class = declare("FilteringSelectClass", null, {
createFileringSelect: function(domNode) {
var memoryStore = new Memory(),
restStore = new JsonRest({
target: "uri/to/get/entries/as/json/list"
}),
cachedStore = new Cache(restStore, memoryStore);
// execute query and cache list of entries in memory store
cachedStore.query();
var widget = new FilteringSelect({
id: "unique_id",
name: "widget_name",
hasDownArrow: true,
invalidMessage: "No element found",
searchAttr: "the name of attribute to filter results",
store: memoryStore
});
if (domNode) {
widget.placeAt(domNode);
}
}
});
return _class;
});
dijit.form.FilteringSelect is a combo box with functionality to query store and filter results by user input.
Usually as store is used dojox.data.QueryReadStore.
Alternative is to use JsonRest to query once the backend and cache the data in memory store.
JsonRest has methods get nad search. Get would be cached and serach wouldn't.
The solution is to assign memory store to FilteringSelect filled out entries from JsonRest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment