How to query a dgrid on multiple columns

℡╲_俬逩灬. 提交于 2019-11-30 20:08:55

问题


Is it possible to create a dgrid query that will search for a regex string on more than one column? Usually the syntax specifies {column1: "foo", column2: "foo"} but that will look for rows where both column1 AND column2 are "foo". But I want to use the same search string against both columns... is that possible and how would I do it? I need something like {column1 || column2 : "foo"}.


回答1:


You can write your own function as I mentioned in my answer to your previous question Is it possible to filter data in a dgrid like you can in a datagrid?

Or you can use Resource Query Language (RQL).

dgrid queries its store, e.g. dojo/store/Memory, which uses dojo/store/util/SimpleQueryEngine by default. All you need to do is to feed store.queryEngine property with QueryEngine of your choice. In the case of RQL, it looks like this (source):

require(["dojo/store/Memory", "rql/js-array", "dgrid/OnDemandGrid"], function(Memory, rql, Grid) {

    var store = new Memory({ data: { /* some data here */}});
    store.queryEngine = rql.query;

    var grid = new Grid({
        store: store,
        columns: { /* some columns here */}
    }, "grid")

});

Now you can query dgrid with RQL syntax. The query to answer your question: (column1=foo|column2=foo).

Please have a look at my jsFiddle (http://jsfiddle.net/phusick/VjJBT). Feel free to fork and experiment either with dgrid itself (there are some predefined queries) or with DOH unit tests (open JS console to see an output):



来源:https://stackoverflow.com/questions/12207364/how-to-query-a-dgrid-on-multiple-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!