1

I have now this code:

define([
    "dojo/_base/declare",
    "dojox/data/JsonRestStore",
    "dojox/grid/LazyTreeGrid",
    "dojox/grid/LazyTreeGridStoreModel"
], function(
    declare, 
    JsonRestStore,
    LazyTreeGrid,
    LazyTreeGridStoreModel
) {
    var layout = { ... },
        store = new JsonRestStore({
            target: "/api/items" // for example
            limitParam: "limit",
            offsetParam: "offset"
        }),

        model = new LazyTreeGridStoreModel({
            serverStore: true,
            store: store,
            childrenAttrs: [ "children" ]
        });

    return declare("CustomTreeGrid", [ LazyTreeGrid ], {
        treeModel: model,
        structure: layout
    });
});

My widget send thousand requests to target URL after startup and freeze my browser. How to fix wrong behavior and save compatibility with RESTful API?

Solution with QueryReadStore work, but not in my situation - Django REST Framework return page with API declaration on GET requests.

Server return data in JSON format:

{
    "items": [ ] //Array of items
    "identifier": "id",
    "numRows": 12 // Total count of items
}

Also I change the server response for returning array. Response headers also contain key "Content-Range: 0-2/3" (for example) and it's not work for me.

Server response headers:

HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Range: items 0-1/2
Content-Type: application/json
Vary: accept

Server response body:

[
    {
        "id": 1,
        "children": false,
        "name": "name1"
    },
    {
        "id": 2,
        "children": false,
        "name": "name2"
    }
]
Dunaevsky Maxim
  • 3,062
  • 4
  • 21
  • 26
  • Do you think you could expose the backend somehow ? helping you without being able to debug is hard. Also, would be nice to see the layout, so we can make a working snippet – ben Jun 09 '16 at 11:17
  • Backend is written with Django REST Framework. User have all permissions, after startup widget create thousand requests to API URL. Server return array with every response, and the grid is empty. – Dunaevsky Maxim Jun 09 '16 at 12:01
  • this is not what I mean. In actually state, your question does not have enough details to help you. You need to share a sample of the backend response, the urls the frontend is calling, the layout you are using... – ben Jun 09 '16 at 12:05

1 Answers1

2

It is pretty hard to make a jsfiddle out of it because you need the server part as well.

I found this implementation: https://github.com/jeremyg484/dojo-json-rest-store

It uses a combination of : dojo.store.Cache, dojo.store.JsonRest, dojo.store.Memory and dojo.data.ObjectStore

Maybe you can do something with it... See how it is used :

myStore = dojo.store.Cache(dojo.store.JsonRest({target:"usstates/"}), dojo.store.Memory());
grid = new dojox.grid.DataGrid({store: dataStore = dojo.data.ObjectStore({objectStore: myStore})

ben
  • 3,558
  • 1
  • 15
  • 28