gridNoColumnSets.set("columnSets", columnExample1); //gridNoColumnSets.set("columnSets", columnExample2);
Take a look at this site where a feature is highlighted from a grid. The feature can be highlighted by moving the mouse over the row in the grid or by clicking on the row. When the grid (dataGrid) is created, I add on listeners: //this highlights the graphic function gridEnter(e) { map.graphics.clear(); var gridId = e.currentTarget.id; var selectedGrid = dijit.byId(gridId); var row = selectedGrid.row(e); graphicHighlight = findGraphicByAttribute(row.data); if (graphicHighlight !== null) { switch (graphicHighlight.geometry.type) { case "point": case "multipoint": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPoint)); break; case "polyline": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPolyline)); break; case "polygon": case "extent": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPolygon)); break; } } }
//this highlights the graphic function gridEnter(e) { map.graphics.clear(); var gridId = e.currentTarget.id; var selectedGrid = dijit.byId(gridId); var row = selectedGrid.row(e); graphicHighlight = findGraphicByAttribute(row.data); if (graphicHighlight !== null) { switch (graphicHighlight.geometry.type) { case "point": case "multipoint": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPoint)); break; case "polyline": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPolyline)); break; case "polygon": case "extent": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPolygon)); break; } } }
var fl = app.map.getLayer("NAME"); var features = fl.getSelectedFeatures(); var symbol1 = fl.getSelectionSymbol(); // var id1 = e.current.id; // var id1 = e.currentTarget.id; // var id1 = e.current.objectID; // var id1 = e.currentTarget.objectID; // var gridId= e.currentTarget.objectID; // var id1= parseInt(gridId); var selectedGraphic1; arrayUtils.forEach(features, function(feature){ if(feature.attributes.OBJECTID === id1){ selectedGraphic1 = feature; } feature.setSymbol(symbol1); });
var columnExample2 = [ [ [ {label: 'id', field: 'id', sortable: false, formatter: function () { return '<img src="images/Identify.png"/>'; }, get: function (object) { return object["objectID"]; } }, {label: 'access', field: 'ACCESSAREA', sortable: true} ], [ {label: 'waterbody', field: 'WATERBODY', colSpan: 2} ], [ {label: 'location', field: 'LOCATION', colSpan: 2, sortable: false} ] ], ];
This line var gridId = e.currentTarget.id;is returning the name of the div that the grid is stored in, not the grid itself. So then this linevar selectedGrid = dijit.byId(gridId);returns an "undefined"
var gridId = e.currentTarget.id;
var selectedGrid = dijit.byId(gridId);
You should get into the habit of using debugging tools like Firebug. These are the errors from your Fiddle[ATTACH=CONFIG]33445[/ATTACH]For the mouseUtils error, you'll have to add the "dgrid/util/mouse" module in your require statement.
Uncaught TypeError: Cannot read property 'row' of undefined (index):807 gridEnter (index):807 (anonymous function) mouse.js:2 (anonymous function) init.js:215 Uncaught TypeError: Cannot read property 'row' of undefined (index):836 2 Uncaught TypeError: Cannot read property 'row' of undefined
Thanks Ken....I I tweaked the JSFiddle to reflect your example sand now when I click the map I dont get any return to the grid...thoughts?http://jsfiddle.net/Jaykapalczynski/HjMB9/17/
var id1 = parseInt(e.currentTarget.id)
var id1 = e.currentTarget.id;
var gridId = e.currentTarget.id; var selectedGrid = dijit.byId(gridId); alert(selectedGrid);
function selectState(e) { alert("select the feature"); var fl = app.map.getLayer("NAME"); var features = fl.getSelectedFeatures(); var symbol1 = fl.getSelectionSymbol(); var id1 = parseInt(e.currentTarget.id); var selectedGraphic1; arrayUtils.forEach(features, function(feature){ if(feature.attributes.OBJECTID === id1){ selectedGraphic1 = feature; } feature.setSymbol(symbol1); }); var mySymbol1 = new SimpleMarkerSymbol().setOutline(null).setColor("#AEC7E3"); selectedGraphic1.setSymbol(mySymbol1); app.map.centerAt(selectedGraphic1.geometry.getExtent().getCenter()); }
Jay, I am trying to help you as best I can without actually doing your work for you.Please reread my previous posts to find the answer to your question.What does e.target.innerHTML equal in this last sample?
dataGrid.on(".dgrid-row:click", gridSelect); dataGrid.on("show", function () { dataGrid.resize(); }); dataGrid.on(mouseUtil.enterRow, gridEnter);
//this highlights the graphic function gridEnter(e) { map.graphics.clear(); var gridId = e.currentTarget.id; var selectedGrid = dijit.byId(gridId); var row = selectedGrid.row(e); graphicHighlight = findGraphicByAttribute(row.data); if (graphicHighlight !== null) { switch (graphicHighlight.geometry.type) { case "point": case "multipoint": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPoint)); break; case "polyline": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPolyline)); break; case "polygon": case "extent": map.graphics.add(new esri.Graphic(graphicHighlight.geometry, symbolHighlightPolygon)); break; } } } //this "flashes" the graphic function gridSelect(e) { var graphicFlash; var gridId = e.currentTarget.id; var selectedGrid = dijit.byId(gridId); var row = selectedGrid.row(e); graphicHighlight = findGraphicByAttribute(row.data); if (graphicHighlight !== null) { switch (graphicHighlight.geometry.type) { case "point": case "multipoint": graphicFlash = new esri.Graphic(graphicHighlight.geometry, symbolFlashPoint) break; case "polyline": graphicFlash = new esri.Graphic(graphicHighlight.geometry, symbolFlashPolyline); break; case "polygon": case "extent": graphicFlash = new esri.Graphic(graphicHighlight.geometry, symbolFlashPolygon); break; } map.graphics.add(graphicFlash); } var shape = graphicFlash.getDojoShape(); var animStroke = fx.animateStroke({ shape: shape, duration: 500, color: { end: new dojo.Color([0, 0, 0, 0]) } }); var animFill = fx.animateFill({ shape: shape, duration: 500, color: { end: new dojo.Color([0, 0, 0, 0]) } }); var anim = dojo.fx.combine([animStroke, animFill]).play(); var animConnect = dojo.connect(anim, "onEnd", function () { map.graphics.remove(graphicFlash); }); } function findGraphicByAttribute(attributes) { for (i = 0; i < layerResultsGraphic.graphics.length; i++) { if (JSON.stringify(layerResultsGraphic.graphics.attributes) === JSON.stringify(attributes)) { return layerResultsGraphic.graphics; } } return null; }
query.objectIds = [parseInt(e.target.innerHTML)];
var columnExample2 = [ [ [ {label: 'id', field: 'id', sortable: false, formatter: function () { return '<img src="images/marker.png"/>'; }, get: function (object) { return object["id"]; } }, {label: 'access', field: 'ACCESSAREA'} ], [ {label: 'location', field: 'LOCATION', colSpan: 2, sortable: false} ] ], ];
function selectState(e) { // select the feature var fl = app.map.getLayer("NAME"); var features = fl.getSelectedFeatures(); var symbol = fl.getSelectionSymbol(); var id = parseInt(e.target.innerHTML); var selectedGraphic; arrayUtils.forEach(features, function(feature){ if(feature.attributes.OBJECTID === id){ selectedGraphic = feature; } feature.setSymbol(symbol); }); var mySymbol = new SimpleMarkerSymbol().setOutline(null).setColor("#AEC7E3"); selectedGraphic.setSymbol(mySymbol); app.map.centerAt(selectedGraphic.geometry.getExtent().getCenter()); }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.