我正在使用dgrid 0.4.0(最新版)和dstore 1.1.0版。现在我对我的dgrid进行了过滤,如
myDgrid.set('collection', myStore.filter(new myStore.Filter({includeInUI: true}).or( {fruit: /apple|banana|orange/i}, {forceSell: true} )) );
myStore有20行,其中forceSell对于任何行都不是真的。果场中有不同的值,但很少行符合上述条件。所有行都将'includeInUI'设置为true。我希望只显示苹果,香蕉或橙色的行,但是当我应用上面的过滤器时,会显示所有20行。
逻辑OR是否无效?或者我做错了什么?当我从Web套接字接收数据时,我还向网格添加行。 (使用dgrid.put)。
我将不胜感激任何帮助。谢谢!
答案 0 :(得分:1)
我的代码中已经设置了IncludeInUI。所以以下陈述有效。
<head>
<meta charset="utf-8">
<title>Test Simple Grid Creation</title>
<meta name="viewport" content="width=570">
<style>
@import "dojo/dojo/resources/dojo.css";
@import "dojo/dijit/themes/claro/claro.css";
.heading {
font-weight: bold;
padding-bottom: 0.25em;
}
.dgrid {
margin: 10px;
}
/* add styles to size this grid appropriately */
#grid {
height: 20em;
}
#grid .field-order {
width: 7%;
}
#grid .field-name {
width: 18%;
}
</style>
<script src="dojo/dojo/dojo.js"
data-dojo-config="async: true"></script>
<script>
var columns = {
id: "ID",
fruit: "Fruit",
includeInUI: "includeInUI",
forceSell: "forceSell"
};
require(["dgrid/OnDemandGrid", "dstore/Memory", "dojo/domReady!"], function(Grid, Memory){
var data1 = [
{id: 1, fruit:"apple", includeInUI:true, forceSell: false},
{id: 2, fruit:"banana", includeInUI:true, forceSell: false},
{id: 3, fruit:"grape", includeInUI:true, forceSell: false},
{id: 4, fruit:"apple", includeInUI:true, forceSell: false},
{id: 5, fruit:"banana", includeInUI:true, forceSell: false},
{id: 6, fruit:"apple", includeInUI:false, forceSell: false},
{id: 7, fruit:"banana", includeInUI:true, forceSell: false},
{id: 8, fruit:"grape", includeInUI:true, forceSell: false},
{id: 9, fruit:"apple", includeInUI:true, forceSell: false},
{id: 10, fruit:"banana", includeInUI:true, forceSell: false}
];
var store = new Memory({data: data1});
window.grid = new Grid({
columns: columns,
collection: store.filter({includeInUI: true}),
idProperty: "id",
id: "myGrid"
}, "grid");
});
</script>
<script>
function filterData() {
require(["dgrid/Grid", "dijit/registry", "dojo/domReady!"], function(Grid, registry){
//var grid = registry.byId('myGrid');
console.log('filterData: ', grid);
var store = grid.collection;
grid.set('collection', store.filter(new store.Filter().or(new store.Filter().eq('fruit','apple'), new store.Filter().eq('forceSell', true))));
});
}
</script>
</head>
<body class="claro">
<h2>A basic grid rendered from an array</h2>
<div id="grid"></div>
<div>Buttons to test filter:
<button onClick="filterData();">Filter</button>
</div>
</body>
</html>
注意:过滤器运算符中不接受RegExp。所以多值的情况可能会出现
bindToController: true
完整代码是:
controllerAs
希望这有助于某人。