Dojo - Filter data store for ComboBox.
http://stackoverflow.com/questions/16329018/dojo-1-8-populate-select-box-with-items-from-database-including-null-values
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/resources/dojo.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojox/grid/resources/Grid.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojox/grid/resources/claroGrid.css">
<link rel="stylesheet" href="http://dojotoolkit.org/documentation/tutorials/1.8/populating_datagrid/demo/style.css">
<link rel="stylesheet" href="http://dojotoolkit.org/documentation/tutorials/resources/style/demo.css">
<div>
<button id="btnLoadStore1">Load StoreData 1</button>
</div>
<div id="node_selBatch"></div>
JavaScript
require(["dojo/parser", "dijit/registry", "dojo/on", "dojo/store/Memory", "dojo/store/util/QueryResults", "dijit/form/ComboBox", "dijit/form/Button"], function (parser, registry, on, Memory, QueryResults, ComboBox, Button) {
function createButton(id) {
return new Button({}, id);
}
function createComboBox(id) {
return new ComboBox({
id: 'ID_selBatch',
value: '',
placeHolder: 'Select...',
searchAttr: 'batch',
style: {
width: '150px'
},
}, id);
}
function createData1() {
var data = [];
for (var i = 0; i < 10; i++) {
data.push({
name: "" + i,
batch: (0 === i % 2) ? "batch" + i : null
});
}
return data;
}
var data = [createData1()];
function createQueryFilter(originalQuery, filter) {
return function () {
var queryResults = originalQuery.apply(this, arguments);
var results = queryResults.filter(filter);
return QueryResults(results);
};
}
parser.parse().then(function () {
var selBatch = createComboBox('node_selBatch');
selBatch.startup();
function click(data) {
console.log("clicked", data);
var memoStore = new Memory({
data: data
});
memoStore.query = createQueryFilter(memoStore.query, function (item) {
console.log(item);
return !!item.batch;
});
selBatch.set('store', memoStore);
selBatch.set('value', '');
console.debug('List of batches per Test is completed! Good OK! ');
}
// Excuse the strange syntax, but I originall operated on an array of buttons
[1].forEach(function (item, idx) {
var btn = createButton('btnLoadStore' + item);
on(btn, 'click', click.bind(null,...