使用AndOrReadStore的Dojo DataGrid过滤器 - 我做错了什么?

时间:2012-01-15 00:12:01

标签: javascript dojo dojox.grid

我有以下代码使用的DataGrid分别有两列Column_AColumn_B

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

这段代码工作正常,找到Column_A里面有单词test的所有行...现在,我想做同样的事情,但看看任一列......逗号转换为AND操作,但我正在寻找OR操作。

我读了AndOrReadStore specs,根据我的理解,我应该可以这样做:

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

然而这不起作用,我没有得到任何结果......我甚至无法使用一个列,就像这样

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

我做错了什么?

谢谢

2 个答案:

答案 0 :(得分:4)

这是一个有效的编程示例(单击按钮调用过滤器:Column_A包含e OR Column_B为300):

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();
});

现在是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>

最后是css(style.css)

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

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

答案 1 :(得分:0)

我查看了您发布的链接,我认为这是一个让括号和括号正确的问题。此外,看起来“复杂查询”用于对象,而“查询”用于字符串:

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

以下是我查看的链接:http://dojotoolkit.org/reference-guide/dojox/data/AndOrReadStore.html#dojox-data-andorreadstore