hi,
i have set of query results,added them to map as feature layer,
results were displaying in attribute table.but when i click on export to csv the operation is failing.
it display's "TypeError: Cannot read property 'query' of undefined" in console.please help me in this.
Thanks&Regards
Tarun
Solved! Go to Solution.
exportToCSV: function(fileName, richTextFieldsToClear) {
if (!this.layerInfo || !this.layer || !this.tableCreated) {
return;
}
// var types = this.layer.types;
this.getSelectedRowsData().then(lang.hitch(
this,
function(datas) {
// seleted data process.
var oid = this.layer.objectIdField;
var _exportData = [];
var isSameProjection = this.layer.fullExtent.spatialReference.equals(
this.map.extent.spatialReference);
var hasArcadeExpressionFields = this._hasArcadeExpressionFields();
// if the output layer's spatial reference is the same as map's, which means
// a spatial reference conversion to make output data (X, Y fileds) consistent with
//layer's original projection system is NOT needed. then we can use data from client side.
// if they are different, then it needs to send a query request to
// server side (handle by "_getExportDataFromServer" method in jimu/CSVUtils.js)
// to get the data with correct spatial reference
if(isSameProjection) {
var rows = array.map(
this._getTableSelectedIds(),
lang.hitch(this, function(id) {
for (var i = 0, len = datas.length; i < len; i++) {
if (datas[i] && datas[i][oid] === id) {
return datas[i];
}
}
return {};
})
);
var _selectedData = rows || [];// get selected data
// if table were in selection mode and no records were selected, we push an
// empty object to _selectedData, for the following logic compatible.
if(_selectedData.length === 0 && this.isSelectionMode()){
_selectedData.push({});
}
_exportData = _selectedData;
if(_selectedData.length === 0 && this.grid.store instanceof Memory){
_exportData = lang.clone(this.grid.store.data);
}
if(_exportData.length){
this._appendXY(_exportData);
}
}
var options = {};
var _outFields = this.getOutFields(!!_exportData.length);
options.datas = _exportData;
options.fromClient = false;
if(this.layer.declaredClass === 'esri.layers.FeatureLayer' && !this.layer.url){
options.fromClient = true;
}
options.withGeometry = this.layer.geometryType === 'esriGeometryPoint';
options.outFields = _outFields;
options.formatNumber = false;
options.formatDate = true;
options.formatCodedValue = true;
options.popupInfo = this.layerInfo.getPopupInfo();
//if spatial reference needs to be converted:
// 1. query data using object ids
options.objectIds = !isSameProjection && this._getExportObjectIds();
// 2. use layer's default spatial reference as the output to do
// the conversion on the server side
options.outSpatialReference = !isSameProjection &&
lang.clone(this.layer.fullExtent.spatialReference);
// pass in rich text fields to be cleared:
options.richTextFieldsToClear = richTextFieldsToClear;
// if the output layer has arcade expressions configured, the computed values
// need to be added to each data to be exported
if(hasArcadeExpressionFields) {
options.arcadeExpressions = {
expressionInfos: this.layerInfo.getPopupInfo().expressionInfos,
layerDefinition: jimuUtils.getFeatureLayerDefinition(this.layer)
};
}
return CSVUtils.exportCSVFromFeatureLayer(
fileName || this.configedInfo.name,
this.layer, options);
}
));
},
Tarun,
The AT widget assumes that a FeatureLayer has a URL and tries to do a QueryTask on the FeatureLayer using it's URL. So because your FeatureLayer that is created using a collection of graphics does not have a URL it fails. The fix has to be made to the AttributeTable\table\_FeatureTable.js exportToCSV function (add lines 6 - 8):
...
var options = {};
var _outFields = this.getOutFields(!!_exportData.length);
options.datas = _exportData;
options.fromClient = false;
if(this.layer.declaredClass === 'esri.layers.FeatureLayer' && !this.layer.url){
options.fromClient = true;
}
...
Thanks for your support ,i have added the code in export to csv function in featuretable.js,still i was unable to close the issue.below im adding export csv function code for your reference please go through it once ,i have highlighted code you given,please help me for resolving the issue.
exportToCSV : function(fileName, richTextFieldsToClear) {
if (!this.layerInfo || !this.layer || !this.tableCreated) {
return;
}
// var types = this.layer.types;
this.getSelectedRowsData().then(lang.hitch(
this,
function(datas) {
// seleted data process.
var oid = this.layer.objectIdField;
var _exportData = [];
var isSameProjection = this.layer.fullExtent.spatialReference.equals(
this.map.extent.spatialReference);
var hasArcadeExpressionFields = this._hasArcadeExpressionFields();
// if the output layer's spatial reference is the same as map's, which means
// a spatial reference conversion to make output data (X, Y fileds) consistent with
//layer's original projection system is NOT needed. then we can use data from client side.
// if they are different, then it needs to send a query request to
// server side (handle by "_getExportDataFromServer" method in jimu/CSVUtils.js)
// to get the data with correct spatial reference
if(isSameProjection) {
var rows = array.map(
this._getTableSelectedIds(),
lang.hitch(this, function(id) {
for (var i = 0, len = datas.length; i < len; i++) {
if (datas && datas[oid] === id) {
return datas;
}
}
return {};
})
);
var _selectedData = rows || [];// get selected data
// if table were in selection mode and no records were selected, we push an
// empty object to _selectedData, for the following logic compatible.
if(_selectedData.length === 0 && this.isSelectionMode()){
_selectedData.push({});
}
_exportData = _selectedData;
if(_selectedData.length === 0 && this.grid.store instanceof Memory){
_exportData = lang.clone(this.grid.store.data);
}
if(_exportData.length){
this._appendXY(_exportData);
}
}
var options = {};
var _outFields = this.getOutFields(!!_exportData.length);
options.datas = _exportData;
options.fromClient = false;
if(this.layer.declaredClass === 'esri.layers.FeatureLayer' && !this.layer.url)
{ options.fromClient = true; }
options.withGeometry = this.layer.geometryType === 'esriGeometryPoint';
options.outFields = _outFields;
options.formatNumber = false;
options.formatDate = true;
options.formatCodedValue = true;
options.popupInfo = this.layerInfo.getPopupInfo();
//if spatial reference needs to be converted:
// 1. query data using object ids
options.objectIds = !isSameProjection && this._getExportObjectIds();
// 2. use layer's default spatial reference as the output to do
// the conversion on the server side
options.outSpatialReference = !isSameProjection &&
lang.clone(this.layer.fullExtent.spatialReference);
// pass in rich text fields to be cleared:
options.richTextFieldsToClear = richTextFieldsToClear;
// if the output layer has arcade expressions configured, the computed values
// need to be added to each data to be exported
if(hasArcadeExpressionFields) {
options.arcadeExpressions = {
expressionInfos: this.layerInfo.getPopupInfo().expressionInfos,
layerDefinition: jimuUtils.getFeatureLayerDefinition(this.layer)
};
}
return CSVUtils.exportCSVFromFeatureLayer(
fileName || this.configedInfo.name,
this.layer, options);
}
));
},
Tarun,
Where did you make these changes (the full path)? If you made them in the client\stemapp\... then you will not see the change until you create a new app. If you made them in the server\apps\[app#]\widgets\AttributeTable\table then, have you cleared your browsers cache?
i have added the code in server/app/widget/attributetable/feature table.js,but not working .i have cleared browser data.still im getting Path not found issue in console
hi robert
i have added the code in server/app/widget/attributetable/feature table.js,but not working .i have cleared browser data.still im getting Path not found issue in console.
Tarun,
Please paste an screenshot of the error. I have tested this on my side using WAB 2.10 and it works fine.
Hi Robert can you send me the export to CSV code with changes you have made,so that I could replace mine,get back to you.
exportToCSV: function(fileName, richTextFieldsToClear) {
if (!this.layerInfo || !this.layer || !this.tableCreated) {
return;
}
// var types = this.layer.types;
this.getSelectedRowsData().then(lang.hitch(
this,
function(datas) {
// seleted data process.
var oid = this.layer.objectIdField;
var _exportData = [];
var isSameProjection = this.layer.fullExtent.spatialReference.equals(
this.map.extent.spatialReference);
var hasArcadeExpressionFields = this._hasArcadeExpressionFields();
// if the output layer's spatial reference is the same as map's, which means
// a spatial reference conversion to make output data (X, Y fileds) consistent with
//layer's original projection system is NOT needed. then we can use data from client side.
// if they are different, then it needs to send a query request to
// server side (handle by "_getExportDataFromServer" method in jimu/CSVUtils.js)
// to get the data with correct spatial reference
if(isSameProjection) {
var rows = array.map(
this._getTableSelectedIds(),
lang.hitch(this, function(id) {
for (var i = 0, len = datas.length; i < len; i++) {
if (datas[i] && datas[i][oid] === id) {
return datas[i];
}
}
return {};
})
);
var _selectedData = rows || [];// get selected data
// if table were in selection mode and no records were selected, we push an
// empty object to _selectedData, for the following logic compatible.
if(_selectedData.length === 0 && this.isSelectionMode()){
_selectedData.push({});
}
_exportData = _selectedData;
if(_selectedData.length === 0 && this.grid.store instanceof Memory){
_exportData = lang.clone(this.grid.store.data);
}
if(_exportData.length){
this._appendXY(_exportData);
}
}
var options = {};
var _outFields = this.getOutFields(!!_exportData.length);
options.datas = _exportData;
options.fromClient = false;
if(this.layer.declaredClass === 'esri.layers.FeatureLayer' && !this.layer.url){
options.fromClient = true;
}
options.withGeometry = this.layer.geometryType === 'esriGeometryPoint';
options.outFields = _outFields;
options.formatNumber = false;
options.formatDate = true;
options.formatCodedValue = true;
options.popupInfo = this.layerInfo.getPopupInfo();
//if spatial reference needs to be converted:
// 1. query data using object ids
options.objectIds = !isSameProjection && this._getExportObjectIds();
// 2. use layer's default spatial reference as the output to do
// the conversion on the server side
options.outSpatialReference = !isSameProjection &&
lang.clone(this.layer.fullExtent.spatialReference);
// pass in rich text fields to be cleared:
options.richTextFieldsToClear = richTextFieldsToClear;
// if the output layer has arcade expressions configured, the computed values
// need to be added to each data to be exported
if(hasArcadeExpressionFields) {
options.arcadeExpressions = {
expressionInfos: this.layerInfo.getPopupInfo().expressionInfos,
layerDefinition: jimuUtils.getFeatureLayerDefinition(this.layer)
};
}
return CSVUtils.exportCSVFromFeatureLayer(
fileName || this.configedInfo.name,
this.layer, options);
}
));
},
hi robert
Thanks for the support,your code is working fine for point geometry layer,but we have polygon geometry results,so we need to add few more line for other geometry types,i have added below code by replacing existing code,problem was solved.
replace this line
options.withGeometry = this.layer.geometryType === 'esriGeometryPoint';
with
if (this.layer.geometryType.length > 0) {
options.withGeometry = true;
}
Finally issue resolved ,Thanks for your support.