[Dojo-interest] populate filteringselect with array

44 views
Skip to first unread message

whim...@aol.com

unread,
Jun 1, 2011, 7:48:49 PM6/1/11
to dojo-i...@mail.dojotoolkit.org
I need to dynamically populate a filterselect with data from an array.
How do I create a dataStore from an array
and then how do I assign it to the filteringselect.

The examples I've seen so far in the documentation get the data from a file or url not from an array.

Thanks for any tips.

Dan


elfwyn

unread,
Jun 2, 2011, 2:14:40 AM6/2/11
to dojo-i...@mail.dojotoolkit.org
Since Dojo 1.6 there is a new Store called dojo.store.Memory.
Since this new Store-API is not yet supported directly by many older
features there
is an adapter class called dojo.data.ObjectStore.

I think that object might work for the filteringselect, but I've only used
it in a DataGrid so far.


data = new dojo.data.ObjectStore(
{ objectStore: new dojo.store.Memory({data:[]}) }
);


--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/populate-filteringselect-with-array-tp3013188p3013980.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

Dojo-i...@mail.dojotoolkit.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

elfwyn

unread,
Jun 2, 2011, 2:40:29 AM6/2/11
to dojo-i...@mail.dojotoolkit.org
The combination of the previous two examples works fine (dojo 1.6x only):


var myStore = new dojo.data.ObjectStore({
objectStore : new dojo.store.Memory({
data:{
identifier:'value',
label:'label',
items:[
{name:'McDonalds',label:'Mc Donalds',value:'MCD'},
{name:'BurgerKing',label:'Burger King',value:'BK'}
]
}
})
});
var select = new dijit.form.FilteringSelect({id:'mySelect',store:myStore});
var hook = dojo.byId("hook").appendChild(select.domNode);


--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/populate-filteringselect-with-array-tp3013188p3014034.html

postoffice

unread,
Jun 2, 2011, 4:58:21 AM6/2/11
to dojo-i...@mail.dojotoolkit.org
You can also do this directly with the ItemFileReadStore, i.e:

// Your array
var myData = [


{name:'McDonalds',label:'Mc Donalds',value:'MCD'},
{name:'BurgerKing',label:'Burger King',value:'BK'}

];

// Create the store from the array. You need to add an additional param (the
identifier), and often you might want to add a label too
var store = new dojo.data.ItemFileReadStore({
data: {
identifier: 'name',
label: 'label',
items: myData
}
})

-----
Tom Elliott / mrtom / postoffice
--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/populate-filteringselect-with-array-tp3013188p3014360.html

whim...@aol.com

unread,
Jun 2, 2011, 12:27:21 PM6/2/11
to dojo-i...@mail.dojotoolkit.org
I can't get the code in this example to work. I get two errors
1. hook is null
2. dojo.store is not defined.

Do I have to require something for the memory object store?
Also what's the purpose of the last line. It seems to reference itself?

Thanks,

Dan

<html>
    <head>
        <link rel="stylesheet" href="dojo161/dijit/themes/claro/claro.css" />
        <script src="dojo161/dojo/dojo.js" data-dojo-config="isDebug: true"></script>    
    </head>
    <body class="claro">
    
         <input id="mySelect" type="text">


    </body>
</html>
       
     <script type="text/javascript">
    dojo.require("dijit.form.FilteringSelect");
    dojo.require("dojo.data.ItemFileReadStore");

var myStore = new dojo.data.ObjectStore({

    objectStore : new dojo.store.Memory({
        data:{
            identifier:'value',
            label:'label',
            items:[
                {name:'McDonalds',label:'Mc Donalds',value:'MCD'},
                {name:'BurgerKing',label:'Burger King',value:'BK'}
            ]
        }
    })
});
var select = new dijit.form.FilteringSelect({id:'mySelect',store:myStore});   
var hook = dojo.byId("hook").appendChild(select.domNode);
</script>
 

elfwyn

unread,
Jun 3, 2011, 12:04:33 PM6/3/11
to dojo-i...@mail.dojotoolkit.org
Sorry - the code was not complete.

You need to require all used dojo classes. In this case:

dojo.require("dojo.store.Memory");
and
dojo.require("dojo.data.ObjectStore");

as well as other widgets as needed.

var hook = dojo.byId("hook").appendChild(select.domNode);

"hook" was just the id of a div that I used to put the widget onto the page.
In the last line I forgot to erease the first part of the statement.
I edited it on the forum, but depending on how you read it, the edit might
not show.
Otherwise its just a way of putting the dijit into the above mentioned
container DIV.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/populate-filteringselect-with-array-tp3013188p3020094.html

whimsica

unread,
Jun 3, 2011, 1:40:32 PM6/3/11
to dojo-i...@mail.dojotoolkit.org
Okay. Got it. Thanks for the example.

Dan

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/populate-filteringselect-with-array-tp3013188p3020470.html

Reply all
Reply to author
Forward
0 new messages