Reputation: 466
I m trying to use a standby widget that will keep loading, till the dojo datagrid is loaded. I m trying this. But, standby widget doesn't appear. It just waits, and loads the data.
require([
"dojox/grid/DataGrid",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/request",
"dojox/widget/Standby",
"dijit/form/Button",
"dojo/domReady!",
],
function (DataGrid, Memory, ObjectStore, request, Standby, Button) {
var standby = new Standby({ target: "grid" });
document.body.appendChild(standby.domNode);
standby.startup();
standby.show();
var grid, dataStore;
request.get("MyFile.aspx", {
handleAs: "json"
}).then(function (data) {
dataStore = new ObjectStore({ objectStore: new Memory({ data: data }) });
grid = dijit.byId("grid");
grid.setStore(dataStore, { id: "*" }, {});
var struct = [
{ name: "Field1", field: "Name", width: "50%" },
{ name: "Field2", field: "Name2", width: "50%" }, ];
grid.setStructure(struct);
grid.startup();
standby.hide();
Upvotes: 0
Views: 590
Reputation: 11
I believe it's just a problem in the order of the calls. You have to first initialize your grid, then initialize the standby, then fetch the data and set it in the grid and then hide the standby. In your case:
require([
"dojox/grid/DataGrid",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/request",
"dojox/widget/Standby",
"dijit/form/Button",
"dojo/domReady!",
],
function (DataGrid, Memory, ObjectStore, request, Standby, Button) {
//Create the grid
var grid = new DataGrid({
query: { id : '*' },
structure : [
{ name: "Field1", field: "Name", width: "50%" },
{ name: "Field2", field: "Name2", width: "50%" }
]
}, 'grid');
grid.startup();
//Create the stand by
var standby = new Standby({ target: "grid" });
document.body.appendChild(standby.domNode);
standby.startup();
standby.show();
//Fetch data
var grid, dataStore;
request.get("teste.php", {
handleAs: "json"
}).then(function (data) {
var grid = dijit.byId('grid');
//Create store and put in the grid
dataStore = new ObjectStore({ objectStore: new Memory({ data: data }) });
grid.setStore(dataStore, { id: "*" }, {});
//Hide standby
standby.hide();
}, function(error) {
console.log(error);
});
}
);
Upvotes: 1