5

I'm trying to use a enhanced grid with Dojo JSONREST and i'm running into some issues. I've been looking up some examples but can't figure out how to do what i need.

In the code below my rest service takes two parameters, and the query on the service works. The problem is that when grid.startup() is called it seems to call the Rest service again, since there are no parameters passed the rest service falls over. What am i doing wrong here?

Also is there any way to update to the store so that is only contains the queried results?, so that when the grid appears it just contains these values?

Appreciate any help or pointers..

ready(function(){

  var grid;

  var store = new JsonRest({
              target: "rest/search"
              });   

  store.query({term: "test", category: "category"},
      {
        start: 10,
        count: 10,
      }).then(function(data){

      // how do i update store with queried results?

      });

  dataStore = new ObjectStore({ objectStore: store });

  /*set up layout*/
  var layout = [[
   {'name': 'Name', 'field': 'col1', noresize: true, 'width': '100%'},
  ]];

  /*create a new grid:*/
  grid = new EnhancedGrid({
      id: 'grid',
      store: dataStore,
      structure: layout,
      selectable: true,
      selector: false,
      selectionMode: 'none',
      escapeHTMLInData: false,
      autoHeight:true
  }, document.createElement('div'));

grid.startup();
}
MiBrock
  • 1,100
  • 1
  • 11
  • 22
blu10
  • 534
  • 2
  • 6
  • 28

2 Answers2

1

Have you tried setting the query parameter of the grid? A link to the docs. And a link to an example.

And by looking at the code in the question, it seems that the grid should display chunks/pages of data - an example using the pagination plugin for the grid.

The filter plugin might also be of interest to you.

undefined
  • 2,051
  • 3
  • 26
  • 47
  • hi there, thanks for that, the setQuery worked. I'm now having trouble refeshing the grid.... if i pass different query parameters to the method the grid doesnt seem to get update. Have you any examples of how to refresh the grid? – blu10 Nov 20 '13 at 12:35
  • The grid has an `update` method. See the [API docs](http://dojotoolkit.org/api/#1_9dojox_grid_EnhancedGrid_update). – undefined Nov 21 '13 at 07:29
  • so if i want to refresh the grid i call another set Query with the new parameters and then call update? – blu10 Nov 22 '13 at 09:46
  • Just `setQuery` and `update` should work. Never tried with a REST store though. – undefined Nov 22 '13 at 12:17
-1

when you define a new grid you have to pass it to dojo:

/*create a new grid:*/
  grid = new EnhancedGrid({
  id: 'grid',
  store: dataStore,
  structure: layout,
  selectable: true,
  selector: false,
  selectionMode: 'none',
  escapeHTMLInData: false,
  autoHeight:true
 }, document.createElement('div'));

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

 grid.startup();
Luca S.
  • 1,132
  • 2
  • 16
  • 31