我使用以下代码处理分别具有两列Column_AColumn_B的DataGrid:

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

这段代码可以正常工作,并找到Column_A中包含单词test的所有行...现在,我想做同样的事情,但是在任一列中查找....逗号转换为AND操作,但我正在寻找或运算。

我阅读了AndOrReadStore specs,根据我的理解,我应该能够执行以下操作:
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%;
}

关于javascript - 使用AndOrReadStore的Dojo DataGrid过滤器-我在做什么错?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8866502/

10-09 22:04