1

I am trying to find out why the filter function isn't working, but I am stucked. This is the first time I am using Dojo but I am not really familliar with that framework. I am trying and searching for maybe 2 or 3 hours but I can't find a solution. Waht I want, is to implement a filter or search mechanism. But it is not working, yet... This is my code:

dojo.require('dojo.store.JsonRest');
dojo.require('dijit.layout.ContentPane');
dojo.require("dijit.form.Button");
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.data.ObjectStore');
dojo.require('dijit.form.TextBox');
dojo.require('dojox.data.AndOrReadStore');
dojo.require('dojo._base.xhr');
dojo.require('dojo.json')
dojo.require('dojo.domReady');
dojo.ready(
function(){
    var appLayout = new dijit.layout.ContentPane({
        id: "appLayout"
    }, "appLayout");

    var textBox = new dijit.form.TextBox({
        name: "searchbox",
        placeHolder: "Search ..."
    });

    var filterButton = new dijit.form.Button({
        label: 'Filter',
        onClick: function () {
            searchWord = textBox.get('value');
            query = "id: '"+searchWord
                +"' OR date_A: '"+searchWord
                    +"' OR dateB: '"+searchWord
                +"' OR product: '"+searchword+"'";
        grid.filter({complexQuery: query}, true);
        }
        });

        store = new dojo.store.JsonRest({target:'products/'});

        grid = new dojox.grid.DataGrid(
        {
            store:dojo.data.ObjectStore({objectStore: store}),
            structure: 
            [
                {name:'id', field: 'id'},         
                {name:'date_A', field: 'dateA'},    
                    {name:'date_B', field: 'dateB'}, 
                    {name:'product' , field: 'product'},          
                ],
            queryOptions: {ignoreCase: true}
            }); 

    textBox.placeAt(appLayout.domNode);
    filterButton.placeAt(appLayout.domNode);
    grid.placeAt(appLayout.domNode);

    appLayout.startup();
}
);

Would be very nice if u can tell me what's wrong with this dojo code... The result is, that the loading icon appears and after a while the unfiltered data is shown... There is no exception thrown. Thanks in advance.

2
  • 1
    FYI: I tried it with another store, called AndOrReadStore, but it isn't working, too.
    – F4k3d
    Commented Jun 25, 2013 at 13:02
  • You should post your comment as an answer.
    – C Snover
    Commented Jun 30, 2013 at 1:19

2 Answers 2

2

Ok, I have solved it with the AndOrReadWriteStore. You can also use an AndOrReadStore. The problem was, that the JSON data wasn't in the right format. You can see the right format here: dojotoolkit.org/api/dojox/data/AndOrReadStore. The other change is: I used the url instead the data attribute inside the store. So finally it is working now. Thx anyway.

2
  • Hi, I'm in a big problem like you, please can you demonstrate more, or show us your code.
    – GingerHead
    Commented Aug 8, 2013 at 8:05
  • 1
    I am sorry, but I can't find it anymore. I t was just a show case for my supervisor. After it I thonk I deleted. If I find the show case again, I will surely post it here. Let me take a look tomorrow at work.
    – F4k3d
    Commented Aug 8, 2013 at 19:21
1

Here's an example of a filter that uses both an AND and an OR:

grid.filter("(genre: 'Horror' && (fname: '" + searchWord + "' || lname:'" + searchWord + "'))")

So the users search word is filtered across fname and lname as an OR but it also searches for genre = Horror as an AND.

This document has other examples... http://livedocs.dojotoolkit.org/dojox/data/AndOrReadStore

Not the answer you're looking for? Browse other questions tagged or ask your own question.