function populateGrid(Memory) { [INDENT]var qt = new QueryTask(window.unitsUrl); var query = new Query(); [/INDENT] query.where = "1=1"; query.returnGeometry = false; query.outFields = window.outFields; qt.execute(query, function(results) { var data = []; var data = array.map(results.features, function(feature) { return { // property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); //if (!grid) { //grid = new Grid({ //columns: { //"id": "ID", //"vehicleId": "Vehicle ID", //"velocity": { "label": "Speed (MPH)", "formatter": dojoNum.format }, //"timestamp": "Time Stamp" //} //}, "grid"); //} //grid.refresh(0.083); var memStore = new Memory({ data: data }); window.grid.set("store", memStore); }); }
map.on("load", function( evt ){ // show the border container now that the dijits // are rendered and the map has loaded domStyle.set(registry.byId("container").domNode, "visibility", "visible"); populateGrid(Memory); // pass a reference to the MemoryStore constructor });
Solved! Go to Solution.
fl.on('update-end', function (r) { console.log(r); //just a check to see that the event fired var data = []; //use the layers graphics instead of making another request var data = array.map(fl.graphics, function (feature) { return { //property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); var memStore = new Memory({ data: data }); window.grid.set("store", memStore); });
I looked at a couple of my grids and I simply create a new store and set it.
layer.on('update', function () { var qt = new QueryTask(window.unitsUrl); var query = new Query(); query.where = "1=1"; query.returnGeometry = false; query.outFields = window.outFields; qt.execute(query, function (results) { var data = []; var data = array.map(results.features, function (feature) { return { // property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); }); window.grid.setStore(new Memory({ data: data })); });
function populateGrid(Memory) { //populate grid code here //now listen for the feature layer update fl.on('update', function () { var qt = new QueryTask(window.unitsUrl); var query = new Query(); query.where = "1=1"; query.returnGeometry = false; query.outFields = window.outFields; qt.execute(query, function (results) { var data = []; var data = array.map(results.features, function (feature) { return { // property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); }); window.grid.setStore(new Memory({ data: data })); }); }
Okay the fiddle helps:function populateGrid(Memory) { //populate grid code here //now listen for the feature layer update fl.on('update', function () { var qt = new QueryTask(window.unitsUrl); var query = new Query(); query.where = "1=1"; query.returnGeometry = false; query.outFields = window.outFields; qt.execute(query, function (results) { var data = []; var data = array.map(results.features, function (feature) { return { // property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); }); window.grid.setStore(new Memory({ data: data })); }); }
Something else you might look into is the feature layer's 'update-end' event and use the features of the feature layer directly to avoid extra requests to the server.
function populateGrid(Memory) { //populate grid code here var qt = new QueryTask(window.unitsUrl); var query = new Query(); query.where = "1=1"; query.returnGeometry = false; query.outFields = window.outFields; qt.execute(query, function(results) { var data = []; var data = array.map(results.features, function(feature) { return { // property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); var memStore = new Memory({ data: data }); window.grid.set("store", memStore); }); //now listen for the feature layer update fl.on('update', function(){ var qt = new QueryTask(window.unitsUrl); var query = new Query(); query.where = "1=1"; query.returnGeometry = false; query.outFields = window.outFields; qt.execute(query, function(results) { var data = []; var data = array.map(results.features, function(feature) { return { //property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); }); var memStore = new Memory({ data: data }); window.grid.set("store", memStore); }); }
fl.on('update-end', function (r) { console.log(r); //just a check to see that the event fired var data = []; //use the layers graphics instead of making another request var data = array.map(fl.graphics, function (feature) { return { //property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); var memStore = new Memory({ data: data }); window.grid.set("store", memStore); });
Try this. Comment out the 'populateGrid' function, just listen for 'update-end', and use the layers graphics to get attribute data.fl.on('update-end', function (r) { console.log(r); //just a check to see that the event fired var data = []; //use the layers graphics instead of making another request var data = array.map(fl.graphics, function (feature) { return { //property names used here match those used when creating the dgrid "id": feature.attributes[window.outFields[0]], "vehicleId": feature.attributes[window.outFields[1]], "velocity": feature.attributes[window.outFields[2]], "timestamp": feature.attributes[window.outFields[3]] } }); var memStore = new Memory({ data: data }); window.grid.set("store", memStore); });
I'm not positive, but 'update-end' should fire when the layer updates due to its updateInterval being set.