<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Custom popup element shows field in Alphabetical Order not order in code in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/custom-popup-element-shows-field-in-alphabetical/m-p/1396434#M58119</link>
    <description>&lt;P&gt;I have customised the popup to use a popupElement to only display fields with content. With the help of ChatGPT this is my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var popupContent = "&amp;lt;table style='border-collapse: collapse;'&amp;gt;";
var cellPadding = "8px"; // Adjust padding as needed

// Field map to hold the field names and their corresponding values
var fieldMap = {
    "Facility ID": $feature.facility_ID,
    "Name": $feature.name,
    "Description": $feature.description,
    "Wharf": $feature.wharf,
    "Berth": $feature.berth,
    "Condition Assessment Rating": $feature.ca_rating,
    "Condition Assessment Date": Text($feature.ca_date, "dddd DD MMMM Y"),
    "Condition Assessment Comments": $feature.ca_comments,
    "Collection Method": $feature.collection_method,
    "Source": $feature.source,
    "Source Date": Text($feature.source_date, "dddd DD MMMM Y")
};

// Add fields to popup content
var i = 0;
for (var fieldName in fieldMap) {
    var fieldValue = fieldMap[fieldName];
    if (fieldValue != null &amp;amp;&amp;amp; fieldValue != "") {
        var rowColor;
        if (i % 2 == 0) {
            rowColor = "#FBFBFB";
        } else {
            rowColor = "#EDEDED";
        }
        popupContent += "&amp;lt;tr style='background-color:" + rowColor + "'&amp;gt;&amp;lt;td style='padding:" + cellPadding + "'&amp;gt;&amp;lt;b&amp;gt;" + fieldName + ":&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td style='padding:" + cellPadding + "'&amp;gt;" + fieldValue + "&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;";
        i++;
    }
}

popupContent += "&amp;lt;/table&amp;gt;";

// Return statement adjusted for popupElement
return { 
type: "text", 
text: popupContent 
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;However the result i'm getting is showing the fields in alphabetical order, not the order listed in my code. I am unsure as to why - can anyone help?&lt;/P&gt;&lt;P&gt;I had alternate code previously that was working the way I wanted, but the request is that it be formatted in a table, like the default ESRI popup but customised to only show fields with content, hence the code.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Feature Layer is hosted in ArcGIS online but cannot be shared publicly.&lt;/P&gt;</description>
    <pubDate>Fri, 15 Mar 2024 05:13:18 GMT</pubDate>
    <dc:creator>Sian_Doherty_GHD</dc:creator>
    <dc:date>2024-03-15T05:13:18Z</dc:date>
    <item>
      <title>Custom popup element shows field in Alphabetical Order not order in code</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/custom-popup-element-shows-field-in-alphabetical/m-p/1396434#M58119</link>
      <description>&lt;P&gt;I have customised the popup to use a popupElement to only display fields with content. With the help of ChatGPT this is my code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var popupContent = "&amp;lt;table style='border-collapse: collapse;'&amp;gt;";
var cellPadding = "8px"; // Adjust padding as needed

// Field map to hold the field names and their corresponding values
var fieldMap = {
    "Facility ID": $feature.facility_ID,
    "Name": $feature.name,
    "Description": $feature.description,
    "Wharf": $feature.wharf,
    "Berth": $feature.berth,
    "Condition Assessment Rating": $feature.ca_rating,
    "Condition Assessment Date": Text($feature.ca_date, "dddd DD MMMM Y"),
    "Condition Assessment Comments": $feature.ca_comments,
    "Collection Method": $feature.collection_method,
    "Source": $feature.source,
    "Source Date": Text($feature.source_date, "dddd DD MMMM Y")
};

// Add fields to popup content
var i = 0;
for (var fieldName in fieldMap) {
    var fieldValue = fieldMap[fieldName];
    if (fieldValue != null &amp;amp;&amp;amp; fieldValue != "") {
        var rowColor;
        if (i % 2 == 0) {
            rowColor = "#FBFBFB";
        } else {
            rowColor = "#EDEDED";
        }
        popupContent += "&amp;lt;tr style='background-color:" + rowColor + "'&amp;gt;&amp;lt;td style='padding:" + cellPadding + "'&amp;gt;&amp;lt;b&amp;gt;" + fieldName + ":&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td style='padding:" + cellPadding + "'&amp;gt;" + fieldValue + "&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;";
        i++;
    }
}

popupContent += "&amp;lt;/table&amp;gt;";

// Return statement adjusted for popupElement
return { 
type: "text", 
text: popupContent 
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;However the result i'm getting is showing the fields in alphabetical order, not the order listed in my code. I am unsure as to why - can anyone help?&lt;/P&gt;&lt;P&gt;I had alternate code previously that was working the way I wanted, but the request is that it be formatted in a table, like the default ESRI popup but customised to only show fields with content, hence the code.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Feature Layer is hosted in ArcGIS online but cannot be shared publicly.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 05:13:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/custom-popup-element-shows-field-in-alphabetical/m-p/1396434#M58119</guid>
      <dc:creator>Sian_Doherty_GHD</dc:creator>
      <dc:date>2024-03-15T05:13:18Z</dc:date>
    </item>
  </channel>
</rss>

