Dijit.form.filteringselect dynamically changes parameters

I have a dijit.form.FilteringSelect component and I want to dynamically change the parameters. But I get the store from dijit.form.Filtering Select its repository property; there is no setter function in the store. (It could be dojo.store.Reader)

So how can I change the dijit.form.FilteringSelect parameter? Should I change it directly using the DOM? Is there a way to update the repository behind dijit.form.FilteringSelect ?

+4
source share
3 answers

There are two types of data storage in dojo:

eg:.

You have an array of countries and you want to use it for filtering:

 [{ abbr: 'ec', name: 'Ecuador', capital: 'Quito' }, { abbr: 'eg', name: 'Egypt', capital: 'Cairo' }, { abbr: 'et', name: 'Ethiopia', capital: 'Addis Ababa' }] 

First of all, you need to create a data warehouse js variable for ItemFileWriteStore.

 <script> dojo.require("dojo.data.ItemFileWriteStore"); dojo.require("dijit.form.FilteringSelect"); var storeData = { identifier: 'abbr', label: 'name', items: //YOUR COUTRIES ARRAY } </script> 

The next step is to declare the filtering option and itemFileWriteStore in the html markup:

 <div dojotype="dojo.data.ItemFileWriteStore" data="storeData" jsid="countryStore"></div> <div dojotype="dijit.form.FilteringSelect" store="countryStore" searchattr="name" id="filtSelect"></div> 

And finally, create special functions for adding / removing / changing elements in the filter selection:

Add new item:

 function addItem() { var usa = countryStore.newItem({ abbr: 'us', name: 'United States', capital: 'Washington DC' }); } 

I hope everything is clear here. Just a small note: the "identifier" field ("abbr" in our case) must be unique in memory

Delete items - for example. deleting all items with the name "United States of America"

 function removeItem() { var gotNames = function (items, request) { for (var i = 0; i < items.length; i++) { countryStore.deleteItem(items[i]); } } countryStore.fetch({ query: { name: "United States of America" }, queryOptions: { ignoreCase: true }, onComplete: gotNames }); } 

As you can see, I created a query that finds items with the name == "United States of America" ​​in the data warehouse. After the request is completed, the "gotNames" function will be called. The gotNames function removes all items that return a request.

And the last function is Edit item.

It looks like a delete function. only one difference:

you must use the setValue() method itemFileWriteStore to change the property of the element:

 countryStore.setValue(item, "name", newValue); 

Here is a page with a working example.

+8
source

I solved the same problem with these suggestions, hope this helps someone.

For Dojo version <1.7

 dijit.byId('myId').store.root[{index of select}].innerText='New text'; dijit.byId('myId').store.root[{index of select}].value='New Value'; 

For Dojo version> = 1.7

 dijit.byId('myId').store.data[{index of select}].name='New Text'; dijit.byId('myId').store.data[{index of select}].value='New Value'; 

To change the displayed text (current selected)

 dijit.byId('myId').textbox.value='New text'; 

You can see this property using Firebug or another debug console.

+3
source

urlPreventCache: true, clearOnClose: true 'properties will force a reboot

 <div data-dojo-type="eco/dojo/data/ItemFileReadStore" data-dojo-props='url:"../json/GetClients", urlPreventCache:true, clearOnClose:true' data-dojo-id="clientStore" ></div> <div id=proposalClient data-dojo-type="dijit/form/FilteringSelect" data-dojo-props="store:clientStore, searchAttr:'clientName', required:'true', pageSize:'15'" ></div> 

and then, on an event / callback / handler where you need / need to reset, the values ​​just do it

 function func-name() { clientStore.url = "../json/GetClients?param=<your-new-search-conditions>"; clientStore.close(); } 
0
source

All Articles