问题描述
我对dojo来说比较新,并且看到了datagrid如何提供动态过滤功能,可以根据您在过滤器文本输入中输入的内容来减少可见行。我没有找到任何关于如何用dgrid做的例子。如果可以做到这一点,请提供一个例子或指向一个提供教程或示例的资源。谢谢!是的,这是可能的。使用 dgrid / OnDemandGrid
并定义查询
函数将返回 true
或 false
根据您在 dojo / store
中为每个行的逻辑启动网格。
我准备了在jsFiddle玩的示例:,所以我不必太多解释:
查询功能:
var filterQuery = function(item,index,items){
var filterString = filter? filter.get(value)+:;
// early exists
if(filterString.length< 2)return true;
if(!item.Name)return false;
//比较
var name =(item.Name +).toLowerCase();
if(〜name.indexOf(filterString.toLowerCase())){return true;}
return false;
};
网格:
var grid = new Grid({
store:store,
query:filterQuery,//< ==用于过滤$ b $的查询函数b列:{
名称:名称,
年份:年,
艺术家:艺术家,
专辑:Album,
类型: 类型
}
},grid);
I'm relatively new to dojo and have seen how datagrid offers a dynamic filtering capability that reduces the visible rows based on what you type into a filter text input. I have not found any examples of how to do it with the dgrid. If it can be done, please provide an example or point me to a resource that offers a tutorial or example. Thanks!
Yes, it is possible. Use dgrid/OnDemandGrid
and define query
function that will return true
or false
based on your logic for each row in dojo/store
powering the grid.
I prepared an example to play with at jsFiddle: http://jsfiddle.net/phusick/7gnFd/, so I do not have to explain too much:
The Query Function:
var filterQuery = function(item, index, items) {
var filterString = filter ? filter.get("value") + "" : "";
// early exists
if (filterString.length < 2) return true;
if (!item.Name) return false;
// compare
var name = (item.Name + "").toLowerCase();
if (~name.indexOf(filterString.toLowerCase())) { return true;}
return false;
};
The Grid:
var grid = new Grid({
store: store,
query: filterQuery, // <== the query function for filtering
columns: {
Name: "Name",
Year: "Year",
Artist: "Artist",
Album: "Album",
Genre: "Genre"
}
}, "grid");
这篇关于可以像在数据网格中一样在dgrid中过滤数据吗?如果是这样,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!