What is wrong with this code? I can get my json and debug it with alert (so that part works with xhr)… so for example, if I do this within the function (of xhr), alert(data[0].name) I get the correct value. There’s not much example neither on the web… but specifying the columns and adding the object store doesn’t show anything… Basically, I just want to load some json file (locally) and render it on the grid, but I will eventually use REST to handle CRUD within my application (So, I will be using JsonRest in a near future).
I think it had to do also with AJAX… I should probably put sync to true (since it seems my global variable doesn,t work properly… undefined).
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dgrid/OnDemandGrid",
"dojo/_base/xhr",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dgrid/Keyboard",
"dgrid/Selection"
], function(
declare,
_WidgetBase,
Grid,
xhr,
Memory,
ObjectStore,
Keyboard,
Selection
){
var dataStore;
xhr.get({
url: "app/resources/data/content.json",
handleAs: "json"
}).then(function(data){
dataStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) });
});
return declare([_WidgetBase, Grid, Keyboard, Selection], {
store: dataStore,
columns:{
name: { label: "name" },
autodelete: { label: "autodelete" },
groupe_id: { label: "groupe_id" },
global: { label: "global" },
date: { label: "date" },
duree: { label: "duree" },
description: { label: "description" },
fichier: { label: "fichier" },
pleinecran: { label: "pleinecran" },
repertoire: { label: "repertoire" },
taille: { label: "taille" },
expiration: { label: "expiration" },
id: { label: "id" },
catergorie: { label: "catergorie" },
brouillon: { label: "brouillon" }
},
postCreate: function() {
}
});
});
For some reason, I just can’t pass a objectStore to a store (for dgrid – onDemandGrid). I separated my “data model” and my viewer this time. So, I have this in app/models (for instance, my code is pretty modular):
Finally, I generate my grid like this by attaching my store to it (app/ui/layout/ContentGrid).