Frage

I have the following code working with a DataGrid that has two column Column_A and Column_B respectively:

grid.filter({Column_A: '*test*', Column_B: '*'}, true)

This code works fine and finds all rows where Column_A has the word test in it... now, I'd like to do the same but look in either column.... the comma translates to an AND operation but I am looking for an OR operation.

I read the AndOrReadStore specs and based on my understanding I should be able to do something like this:

grid.filter({complexQuery: "Column_A: '*test*' OR Column_B: '*'"}, true)

however this does not work and I don't get any results... I can't even get it to work with one column, like this

grid.filter({complexQuery: "Column_A: '*test*'"}, true)

What am I doing wrong?

Thank you

War es hilfreich?

Lösung

Here is a working programmatic example (Click the button to invoke the filter: Column_A contains an e OR Column_B is 300):

the JavaScript (script.js):

dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.form.Button");
dojo.require("dojox.grid.DataGrid");
dojo.require('dojox.data.AndOrReadStore');

dojo.ready(function(){  
var appLayout = new dijit.layout.ContentPane({
    id: "appLayout"
}, "appLayout");

var data = {
  'items': [
    {'Column_A': 'alpha', 'Column_B': '100'},
    {'Column_A': 'beta',  'Column_B': '200'},
    {'Column_A': 'gamma', 'Column_B': '300'},
    {'Column_A': 'delta', 'Column_B': '400'}
  ]
};
var store = new dojox.data.AndOrReadStore({
    data: data      
});


var layout = [[ 
  {name : 'A', field : 'Column_A', width : '125px'},
  {name : 'B', field : 'Column_B', width : '100%'} 
]];


var grid = new dojox.grid.DataGrid({
    structure : layout,
    store: store,
    queryOptions: {ignoreCase: true}
});


    var filterButton = new dijit.form.Button({
        label: "Filter",
        onClick: function () {
            grid.filter({complexQuery: "Column_A: '*e*' OR 'Column_B: '300'"});
        }
    });

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

    appLayout.startup();
});

And now the html (index.html)

<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>DataGrid with AndOrReadStore</title>

    <link rel="stylesheet" href="style.css" media="screen"/>   
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/themes/claro/claro.css" />
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dijit/themes/claro/document.css" />   
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojox/layout/resources/ExpandoPane.css" />
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojox/grid/resources/claroGrid.css">
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojox/grid/enhanced/resources/claro/EnhancedGrid.css">

    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js" type="text/javascript"></script>
    <script src="script.js" type="text/javascript"></script>
  </head>

  <body class="claro">
    <div id="appLayout"></div>
  </body>
</html>

And finally the css (style.css)

html, body {
  width: 100%; height: 100%;
  margin: 0; padding: 0; 
  overflow: hidden;     
}   

#appLayout {
  width: 100%; height: 100%;
} 

Andere Tipps

I looked at the link you posted, and I think it's an issue of getting the brackets and parenthesis correct. Also, it looks like the 'complex query' is used for objects, whereas 'query' is used for strings:

grid.filter({query: ("Column_A: '*test*' OR Column_B: '*'")}, true);

Here's the link I looked at: http://dojotoolkit.org/reference-guide/dojox/data/AndOrReadStore.html#dojox-data-andorreadstore

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top