I am trying to limit the fields exported in the "export to CSV" option for the query widget. I would like to just limit the field exported to the same fields that are within our popups for our parcels. I know i might have to dive into the code in the CSV.Utils.js for the application. Any direction or help to lead me to a work around would be great. I am working with Web App Builder for Developers 2.4.
Kyle,
The layer.id will not be 5 it will be something like "graphicsLayer4". I would use the layer.name instead:
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">===</SPAN> <SPAN class="string token">"Owner Parcels _Query Result"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
I have a question that seems very related to these questions, but concerns getting data from related records. I would like to print my related table with information in it on the parent featureclass. Is there a way to alter this line:
layer.fields = ["PIN"];
To something like ["relatedTbl.PIN"] to get related table information? I have guys in the field collecting with Collector (where I can't customize the data that goes into the fields). I can't find a way to relate the data when I export into csv once the guys get back to their desks. Just printing the csv table of the inspection doesn't indicate what it was an inspection for. Any ideas?
Thanks for the reply Robert. I will try this out. Cheers
Kym,
You would filter the fields array before you pass it to the lang.clone.
<SPAN class="keyword token">var</SPAN> myFlds <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"x"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"y"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"z"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> fFlds <SPAN class="operator token">=</SPAN> array<SPAN class="punctuation token">.</SPAN><SPAN class="token function">filter</SPAN><SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">.</SPAN>fields<SPAN class="punctuation token">,</SPAN> lang<SPAN class="punctuation token">.</SPAN><SPAN class="token function">hitch</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>fldInfo<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> myFlds<SPAN class="punctuation token">.</SPAN><SPAN class="token function">indexOf</SPAN><SPAN class="punctuation token">(</SPAN>fldInfo<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">;</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> featureSet<SPAN class="punctuation token">.</SPAN>fields <SPAN class="operator token">=</SPAN> lang<SPAN class="punctuation token">.</SPAN><SPAN class="token function">clone</SPAN><SPAN class="punctuation token">(</SPAN>fFlds<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Hi
I am also trying to limit the number of fields that can be viewed in the csv results from query widget.
At present it shows everything. I want to limit this right down to 4 fields. How do I go about doing this
Robert you mentioned making changes to this line
"In the SingleQueryResult.js file find this line
featureSet<SPAN style="color: #000000; ">.</SPAN>fields <SPAN style="color: #000000; ">=</SPAN> lang<SPAN style="color: #000000;"><SPAN>.</SPAN><SPAN>clone</SPAN><SPAN>(</SPAN></SPAN>layer<SPAN style="color: #000000; ">.</SPAN>fields<SPAN style="color: #000000;"><SPAN>)</SPAN><SPAN>;</SPAN></SPAN><SPAN></SPAN>
This is where the fields that are exported are specified. You could modify the available field here before it is passed to the ExportToCSV.js"
I am not exactly sure how to proceed. in the brackets should I be replacing text layer.fields with the titles of the fields I want included?
Thanks
The search results layer is a client side FeatureLayer from a FeatureCollection and thus the attributes will be formatted using the eSearch widget settings.
_getFeatureSet: function(){ var layer = this.currentSearchLayer; var featureSet = new FeatureSet(); if (layer.name==="Search Results: Parcel"){ layer.fields = ["PIN]; } else if (layer.name==="Address _Query Result") { layer.fields = ["ADDRESS"]; }<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
So I have tried to make those adjustments in the Widget.js for the eSearch widget. Upon exporting the data as a CSV, it seems to be carrying over the result formatting that is specified in the app configuration. I am a little confused as to how the currentSearchLayer is create and or what exactly that returns. Is there something else i should be specifiying?
thanks,
Kyle
In the eSearch you would use "Search Results: Whatever the name of the layer is in the LayerList widget"
Robert,
If i wanted to accomplish the same task in your Enhanced Search widget, how would the layer.name string be formatted? It was easy to figure out how the layer.name was formatted in the Query widget but with your Enhanced Search widget i am having a little bit more difficulty.
This sounds like a better way of accomplishing what I would like to do. I have the if else statement created but I am having trouble getting the layerID from the layer variable. Should i create another var that gets the layer info from the query.resultLayer? It is probably really simply what i am tyring to do but i am somewhat new to custom coding.
var layer = this.currentAttrs.query.resultLayer; var featureSet = new FeatureSet(); if (layer.id===5){ layer.fields = ["PIN"]; } else if (layer.id===1) { layer.fields = ["ADDRESS"]; } <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
What you are asking for would be difficult. The easier way would be to check which layer id you are working with and apply the code change based on the proper layer or not.
So I have been able to get result that i am looking for, however it is being applied to all the layers within my query widget. I have both parcels and address points being used in my query widget When i go to export out address points results as a CSV the results will only list the "PIN" field. Which in my address point data is not a valid field.
layer.fields = ["PIN"] featureSet.fields = lang.clone(layer.fields);<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
Is there a way that i can call the Layer's popup configuration from the web map as the fields that should be exported? So instead of doing the above code, limit the featureSet.fields to the web map popup that is specified in the query configuration dialogue box?
In the SingleQueryResult.js file find this line
featureSet<SPAN class="punctuation token">.</SPAN>fields <SPAN class="operator token">=</SPAN> lang<SPAN class="punctuation token">.</SPAN><SPAN class="token function">clone</SPAN><SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">.</SPAN>fields<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
This is where the fields that are exported are specified. You could modify the available field here before it is passed to the ExportToCSV.js
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.