我有以下代码用于分别具有两列Column_A
和Column_B
的DataGrid:
grid.filter({Column_A: '*test*', Column_B: '*'}, true)
这段代码运行良好,可以查找Column_A
中包含单词test的所有行……现在,我想做同样的操作,但查看任意一列。。。。逗号翻译成AND运算,但我正在寻找OR运算。
我阅读了AndOrReadStore的规范,根据我的理解,我应该能够做这样的事情:
grid.filter({complexQuery: "Column_A: '*test*' OR Column_B: '*'"}, true)
然而,这不起作用,我没有得到任何结果。。。我甚至不能让它与一个专栏一起工作,比如这个
grid.filter({complexQuery: "Column_A: '*test*'"}, true)
我做错了什么?
感谢
下面是一个工作程序示例(单击按钮调用筛选器:Column_a包含e或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%;
}
我看了你发布的链接,我认为这是一个正确使用括号的问题。此外,看起来"复杂查询"用于对象,而"查询"用于字符串:
grid.filter({query: ("Column_A: '*test*' OR Column_B: '*'")}, true);
以下是我查看的链接:http://dojotoolkit.org/reference-guide/dojox/data/AndOrReadStore.html#dojox-数据和数据存储