可以像在数据网格中一样在dgrid中过滤数据吗?如果是这样,怎么样? [英] Is it possible to filter data in a dgrid like you can in a datagrid? If so, how?

查看:87
本文介绍了可以像在数据网格中一样在dgrid中过滤数据吗?如果是这样,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对dojo来说比较新,并且看到了datagrid如何提供动态过滤功能,可以根据您在过滤器文本输入中输入的内容来减少可见行。我没有找到任何关于如何用dgrid做的例子。如果可以做到这一点,请提供一个例子或指向一个提供教程或示例的资源。谢谢!

解决方案

是的,这是可能的。使用 dgrid / OnDemandGrid 并定义查询函数将返回 true false 根据您在 dojo / store 中为每个行的逻辑启动网格。



我准备了在jsFiddle玩的示例: http://jsfiddle.net/phusick/7gnFd/ ,所以我不必太多解释:





查询功能:

  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中过滤数据吗?如果是这样,怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆