Search code examples
javascriptdojodojox.grid.datagriddojox.grid

Using Dojo Grid with a Memory store


I'm having some problems getting the Dojo Grid widget to work.

The grid itself is added declaratively:

<table data-dojo-type="dojox.grid.DataGrid" data-dojo-attach-point="relationshipsGrid"></table>

Next, I'm trying to bind the grid to a Memory data store:

var relationships = [
                  { id: 1, market: "SE", entity: "An object" },
                  { id: 2, market: "SE", entity: "Another object" },
                  { id: 3, market: "SE", entity: "Yet another object" }
                ];

                var store = new Memory({ data: relationships });

                var layout = [[
                  { 'name': 'ID', 'field': 'id', 'width': '10px' },
                  { 'name': 'Market', 'field': 'market', 'width': '30px' },
                  { 'name': 'Entity', 'field': 'entity', 'width': '100px' }
                ]];

                this.relationshipsGrid.structure = layout;
                this.relationshipsGrid.store = store;
                this.relationshipsGrid.startup();

However, all I end up with is an empty, 0-height grid. If I explicitly set a height to it I just get an empty grayish area. There is a lot of Dojo markup rendered, but without any items from my store.

I'm sure I'm overlooking something trivial (hopefully), but any help is greatly appreciated! :)


Solution

  • dojox/grid does not support the dojo/store API directly, and is also no longer maintained.

    You have a few options:

    • Wrap a dojo/store with dojo/data/ObjectStore to convert it to the old dojo/data API that dojox/grid understands
    • Use a dojo/data store directly (not recommended, since it's been deprecated for years)
    • Use a more modern grid package like dgrid (0.3.x supports dojo/store; 0.4.x supports dstore which aims to be the next generation of dojo stores)