F4k3d
F4k3d

Reputation: 703

Dojo DataGrid filtering with complexQuery not working

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.

Upvotes: 1

Views: 1824

Answers (2)

Jerry
Jerry

Reputation: 46

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

Upvotes: 1

F4k3d
F4k3d

Reputation: 703

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.

Upvotes: 2

Related Questions