[Dojo-interest] how to use "or" conditional in grid.setQuery?

175 views
Skip to first unread message

Felipe Ortiz M.

unread,
Feb 3, 2012, 2:13:16 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
Anybody nows, how can I put something like "category=1 || category=2", as part of my query options in a dojox.grid.DataGrid ?

the following code works, but I would like to include other categories:

 dijit.byId(grid_id).setQuery({categoria:1});  

--
------------------------------------------------------
Felipe A. Ortiz Marín.

frankf

unread,
Feb 3, 2012, 2:28:42 AM2/3/12
to dojo-i...@mail.dojotoolkit.org

fortizma wrote

>
> Anybody nows, how can I put something like "category=1 || category=2", as
> part of my query options in a dojox.grid.DataGrid ?
>
> the following code works, but I would like to include other categories:
>
> dijit.byId(grid_id).setQuery({categoria:1});
>
Which datastore are you using? If you can use the AndOr____Store, it
supports that type of complex query. I believe another store or two may
also support complex queries.

If you can use the EnhancedGrid, it supports a Filter function that supports
complex queries.

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/how-to-use-or-conditional-in-grid-setQuery-tp3712349p3712365.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

Dojo-i...@mail.dojotoolkit.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Felipe Ortiz M.

unread,
Feb 3, 2012, 2:38:10 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
Thanks for your prompt reply. 

I'm using ItemFileReadStore. How can I do it?

frankf

unread,
Feb 3, 2012, 2:49:54 AM2/3/12
to dojo-i...@mail.dojotoolkit.org

fortizma wrote

>
> I'm using ItemFileReadStore. How can I do it?
>
The AndOrReadStore is a drop in replacement for ItemFileReadStore and is
identical except that it supports complex queries. Note that the AndOr___
stores are dojox. not dojo.

See http://dojotoolkit.org/reference-guide/dojox/data/AndOrReadStore.html


--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/how-to-use-or-conditional-in-grid-setQuery-tp3712349p3712394.html

Felipe Ortiz M.

unread,
Feb 3, 2012, 3:12:09 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
Ok Frank, thanks. 

I'm using now dojox.data.AndOrReadStore and is working well as store for the dojox.grid.DataGrid.

However, what I'm doing wrong that the following codes are not working well:

gridID2.store.fetch({query: "categoria:3 AND categoria:4"});

gridID2.setQuery({query: "categoria:3 AND categoria:4"});

gridID2 is dijit.byId(grid_id2);

thanks again for your time and support. 

Felipe Ortiz M.

unread,
Feb 3, 2012, 3:15:27 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
code1-> gridID2.store.fetch({query: "categoria:3 OR categoria:4"});

code2-> gridID2.setQuery({query: "categoria:3 OR categoria:4"});

frankf

unread,
Feb 3, 2012, 3:25:23 AM2/3/12
to dojo-i...@mail.dojotoolkit.org

fortizma wrote
>
> I'm using now dojox.data.AndOrReadStore and is working well as store for
> the
> dojox.grid.DataGrid.
>
> However, what I'm doing wrong that the following codes are not working
> well:
>
> gridID2.store.fetch({query: "categoria:3 AND categoria:4"});
>
> gridID2.setQuery({query: "categoria:3 AND categoria:4"});
>
> gridID2 is dijit.byId(grid_id2);
>
Try:

gridID2.store.fetch({query: {complexQuery:"categoria:3 OR categoria:4"}});
gridID2.setQuery({query: {complexQuery:"categoria:3 OR categoria:4"}});

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/how-to-use-or-conditional-in-grid-setQuery-tp3712349p3712443.html

Felipe Ortiz M.

unread,
Feb 3, 2012, 3:36:40 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
still not. 

gridID2.setQuery({query: {complexQuery:"categoria:3 OR categoria:4"}});

neither code options separately shown the results of the query on the grid. 

how could I console.log the results of the query? 

is the query creating new data for the store? so should I use setStore after the query to populate the grid?, or just with the last code the grid would be populated?


frankf

unread,
Feb 3, 2012, 3:44:38 AM2/3/12
to dojo-i...@mail.dojotoolkit.org

fortizma wrote

>
> still not.
>
> gridID2.setQuery({query: {complexQuery:"categoria:3 OR categoria:4"}});
>
> neither code options separately shown the results of the query on the
> grid.
>
> how could I console.log the results of the query?
>
> is the query creating new data for the store? so should I use setStore
> after the query to populate the grid?, or just with the last code the grid
> would be populated?
>
The query is not creating new data for the store. It is only "filtering"
the data existing in the store. You may need to do a grid.refresh(), but I
wouldn't think so. I'll look deeper tomorrow (late night...).

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/how-to-use-or-conditional-in-grid-setQuery-tp3712349p3712472.html

Felipe Ortiz M.

unread,
Feb 3, 2012, 5:17:01 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
Let me explain better my idea:

I have 2 grids, the main idea is populate the second one based on the rows selected in the first one. 

this is my second grid:

<div dojoType="dojox.data.AndOrReadStore" jsId="tipo_inmueble" url="/data/tipoinmueblejson/"></div>
<table  
dojoType="dojox.grid.DataGrid" 
id="tipo_inmueble"
store="tipo_inmueble" 
clientSort="true"
escapeHTMLInData="false"
>
<thead>
<tr>
<th name='Predio' field="nombre" width="100%" nowrap ></th>
</tr>
</thead>
</table>

when the event onClickRow is fired in the first grid, I'm calling a function defined with the following code:

var gridID1 = dijit.byId(grid_id1);
var gridID2 = dijit.byId(grid_id2);
var items = gridID1.selection.getSelected();

if(items.length){
var valuex = "";
for(i=0;i<(items.length);i++){
if(i<(items.length-1)){
valuex = valuex + "categoria:"+ items[i].id[0] + " OR ";
}else{
valuex = valuex + "categoria:"+ items[i].id[0];
}
}
console.log(valuex); // categoria:2 OR categoria:3
gridID2.setQuery({valuex});
}

The first time  gridID2 is populated well, but after the query  gridID2 is blank. that's just the issue I'm having. 

it seems to be that the setQuery function is not working well in AndOrReadStore, when I use ItemFileReadStore setQuerysetQuery({categoria:2}); works well. 

I have also tried directyly to put:
gridID2.setQuery({query: {complexQuery:"categoria:3 OR categoria:4"}});

and //gridID2.store.fetch({query: {complexQuery:"categoria:3 OR categoria:4"}});

but neither works. 

Thanks for your comments.  

Felipe Ortiz M.

unread,
Feb 3, 2012, 5:26:03 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
what I'm putting exactly in the query is gridID2.setQuery({query: {complexQuery:valuex});

but valuex can't no be a simple string like category:2 OR category:3

humm. 

frankf

unread,
Feb 3, 2012, 10:15:46 AM2/3/12
to dojo-i...@mail.dojotoolkit.org
Make sure the following simple (programmatic) test file works for you (works
here). If so, it will validate that you can do complex queries in DataGrid
using the AndOr_____Store. If this works, but your two grid setup doesn't,
then there may be a problem in how you are retrieving/converting the items
from the first grid or in the syntax (quotes, brackets, etc.) within the
query.

Note: some of initial html and trailing html tags code/tags are omitted
below so that the forum software will display the code formatted reasonably.

dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.data.AndOrWriteStore");

dojo.ready(function(){
/*set up data store*/
var data = {
identifier: 'id',
items: []
};
var data_list = [
{ col1: "normal", col2: false, col3: 'But are not followed by two
hexadecimal', col4: 29.91},
{ col1: "important", col2: false, col3: 'Because a % sign always
indicates', col4: 9.33},
{ col1: "important", col2: false, col3: 'Signs can be selectively',
col4: 19.34}
];
var rows = 60;
for(var i=0, l=data_list.length; i<rows; i++){
data.items.push(dojo.mixin({ id: i+1 }, data_list[i%l]));
}
var store = new dojox.data.AndOrWriteStore({data: data});

/*set up layout*/
var layout = [[
{'name': 'Column 1', 'field': 'id', 'width': '100px'},
{'name': 'Column 2', 'field': 'col2', 'width': '100px'},
{'name': 'Column 3', 'field': 'col3', 'width': '200px'},
{'name': 'Column 4', 'field': 'col4', 'width': '150px'}
]];

/*create a new grid:*/
var grid = new dojox.grid.DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'},
document.createElement('div'));

/*append the new grid to the div*/
dojo.byId(&quot;gridDiv&quot;).appendChild(grid.domNode);

/*Call startup() to render the grid*/
grid.startup();
});
function filterItOne() {
dijit.byId('grid').setQuery({complexQuery:&quot;id:3 OR id:2&quot;});
}
function filterItTwo() {
dijit.byId('grid').setQuery({complexQuery:&quot;id:3 OR
col4:'9.33'&quot;});
}
function resetFilter() {
dijit.byId('grid').setQuery({id:&quot;*&quot;});
}
&lt;/script>
</head>
<body class="tundra">
<button onclick="filterItOne();">Filter on: "id:3 OR id:2"</button><button
onclick="filterItTwo();">Filter on: "id:3 OR col4:'9.33'"</button><button
onclick="resetFilter();">Reset Filter</button>
<div id="gridDiv"></div>
</body>

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/how-to-use-or-conditional-in-grid-setQuery-tp3712349p3713344.html

Felipe Ortiz M.

unread,
Feb 3, 2012, 12:03:51 PM2/3/12
to dojo-i...@mail.dojotoolkit.org
Ok, Frank. It's working now. 

The issue was that the syntax for complexqueries 

is not: gridID2.setQuery({query: {complexQuery:"categoria:3 OR categoria:4"}});

the correct is avoiding "query:" gridID2.setQuery({complexQuery:"categoria:3 OR categoria:4"});

My app is now working perfect. Thank you so much for you time and support. 

Regards, 
Reply all
Reply to author
Forward
0 new messages