<?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 Field Aliases inside Query Widget in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-field-aliases-inside-query-widget/m-p/1210582#M78620</link>
    <description>&lt;P&gt;Hello, I'm trying to come up with custom field labels for my query widget in a map I'm creating. I'm using this sample code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/query-related-features/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/query-related-features/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the query is run, the fields for the table appears as such:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rice_GIS_0-1662586846562.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50688i253A76918ADAFB6D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rice_GIS_0-1662586846562.png" alt="Rice_GIS_0-1662586846562.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My aim is to customize the field labels to show cleaner titles like, "City" for "NAME" and "Sum Population" instead of "SUM_POPULATION".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would anyone know what I need to add and where to add it to achieve this goal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The entire code for the aforementioned map is here.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1, maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;title&amp;gt;
      Query Related Features | Sample | ArcGIS API for JavaScript 4.24
    &amp;lt;/title&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
      #gridDiv {
        padding: 10px;
        max-width: 300px;
      }
      #viewDiv {
        height: 100%;
        width: 100%;
      }
      #clearButton {
        margin-top:5px;
        display: none;
      }
      .dgrid {
        height: auto !important;
      }
      .dgrid .dgrid-scroller {
        position: relative;
        max-height: 200px;
        overflow: auto;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://unpkg.com/dgrid@1.2.1/css/dgrid.css" /&amp;gt;
    &amp;lt;script src="https://unpkg.com/dgrid@1.2.1/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.24/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.24/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script&amp;gt;
      require([
        "esri/Map",
        "esri/Basemap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend",
        "esri/widgets/Expand",
        "dgrid/Grid"
      ], function (Map, Basemap, MapView, FeatureLayer, Legend, Expand, Grid) {
        // Create the layer
        const layer = new FeatureLayer({
          portalItem: {
            id: "7a301e848a7c4bfcaefdac4fe98a7f99"
          },
          outFields: ["*"]
        });

        // Setup the map
        const basemap = new Basemap({
          portalItem: {
            id: "00c8181753cd4673810a1ede1f52a922"
          }
        });

        const map = new Map({
          basemap: basemap,
          layers: [layer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-98.5795, 39.8282],
          zoom: 3,
          popup: {
            autoOpenEnabled: false
          }
        });

        const legend = new Legend({ view: view });
        // Expand widget to expand and contract the legend widget
        const legendExpand = new Expand({
          expandTooltip: "Show Legend",
          expanded: false,
          view: view,
          content: legend
        });

        // Add widgets to the view
        view.ui.add(document.getElementById("gridDiv"), "bottom-left");
        view.ui.add(legendExpand, "top-right");

        // Initialize variables
        let highlight, grid;

        // call clearMap method when clear is clicked
        const clearbutton = document.getElementById("clearButton");
        clearbutton.addEventListener("click", clearMap);

        layer.load().then(function () {
          return (g = new Grid());
        });

        view.on("click", function (event) {
          clearMap();
          queryFeatures(event);
        });

        function queryFeatures(screenPoint) {
          const point = view.toMap(screenPoint);

          // Query the for the feature ids where the user clicked
          layer
            .queryObjectIds({
              geometry: point,
              spatialRelationship: "intersects",
              returnGeometry: false,
              outFields: ["*"]
            })

            .then(function (objectIds) {
              if (!objectIds.length) {
                return;
              }

              // Highlight the area returned from the first query
              view.whenLayerView(layer).then(function (layerView) {
                if (highlight) {
                  highlight.remove();
                }
                highlight = layerView.highlight(objectIds);
              });

              // Query the for the related features for the features ids found
              return layer.queryRelatedFeatures({
                outFields: ["NAME", "SUM_POPULATION"],
                relationshipId: layer.relationships[0].id,
                objectIds: objectIds
              });
            })

            .then(function (relatedFeatureSetByObjectId) {
              if (!relatedFeatureSetByObjectId) {
                return;
              }
              // Create a grid with the data
              Object.keys(relatedFeatureSetByObjectId).forEach(function (
                objectId
              ) {
                // get the attributes of the FeatureSet
                const relatedFeatureSet = relatedFeatureSetByObjectId[objectId];
                const rows = relatedFeatureSet.features.map(function (feature) {
                  return feature.attributes;
                });

                if (!rows.length) {
                  return;
                }

                // create a new div for the grid of related features
                // append to queryResults div inside of the gridDiv
                const gridDiv = document.createElement("div");
                const results = document.getElementById("queryResults");
                results.appendChild(gridDiv);

                // destroy current grid if exists
                if (grid) {
                  grid.destroy();
                }
                // create new grid to hold the results of the query
                grid = new Grid(
                  {
                    columns: Object.keys(rows[0]).map(function (fieldName) {
                      return {
                        label: fieldName,
                        field: fieldName,
                        sortable: true
                      };
                    })
                  },
                  gridDiv
                );

                // add the data to the grid
                grid.renderArray(rows);
              });
              clearbutton.style.display = "inline";
            })
            .catch(function (error) {
              console.error(error);
            });
        }

        function clearMap() {
          if (highlight) {
            highlight.remove();
          }
          if (grid) {
            grid.destroy();
          }
          clearbutton.style.display = "none";
        }
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;div id="gridDiv" class="esri-widget"&amp;gt;
      &amp;lt;h2&amp;gt;US Cities&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;
        Click on a hexagon in the map to view the US cities located in that
        area.
      &amp;lt;/p&amp;gt;
      &amp;lt;div id="queryResults"&amp;gt;&amp;lt;/div&amp;gt;
      &amp;lt;button id="clearButton" class="esri-widget"&amp;gt;Clear Query&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Sep 2022 21:43:10 GMT</pubDate>
    <dc:creator>Rice_GIS</dc:creator>
    <dc:date>2022-09-07T21:43:10Z</dc:date>
    <item>
      <title>Custom Field Aliases inside Query Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-field-aliases-inside-query-widget/m-p/1210582#M78620</link>
      <description>&lt;P&gt;Hello, I'm trying to come up with custom field labels for my query widget in a map I'm creating. I'm using this sample code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/query-related-features/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/query-related-features/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the query is run, the fields for the table appears as such:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Rice_GIS_0-1662586846562.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/50688i253A76918ADAFB6D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Rice_GIS_0-1662586846562.png" alt="Rice_GIS_0-1662586846562.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My aim is to customize the field labels to show cleaner titles like, "City" for "NAME" and "Sum Population" instead of "SUM_POPULATION".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would anyone know what I need to add and where to add it to achieve this goal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The entire code for the aforementioned map is here.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1, maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;title&amp;gt;
      Query Related Features | Sample | ArcGIS API for JavaScript 4.24
    &amp;lt;/title&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
      #gridDiv {
        padding: 10px;
        max-width: 300px;
      }
      #viewDiv {
        height: 100%;
        width: 100%;
      }
      #clearButton {
        margin-top:5px;
        display: none;
      }
      .dgrid {
        height: auto !important;
      }
      .dgrid .dgrid-scroller {
        position: relative;
        max-height: 200px;
        overflow: auto;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://unpkg.com/dgrid@1.2.1/css/dgrid.css" /&amp;gt;
    &amp;lt;script src="https://unpkg.com/dgrid@1.2.1/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.24/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.24/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script&amp;gt;
      require([
        "esri/Map",
        "esri/Basemap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend",
        "esri/widgets/Expand",
        "dgrid/Grid"
      ], function (Map, Basemap, MapView, FeatureLayer, Legend, Expand, Grid) {
        // Create the layer
        const layer = new FeatureLayer({
          portalItem: {
            id: "7a301e848a7c4bfcaefdac4fe98a7f99"
          },
          outFields: ["*"]
        });

        // Setup the map
        const basemap = new Basemap({
          portalItem: {
            id: "00c8181753cd4673810a1ede1f52a922"
          }
        });

        const map = new Map({
          basemap: basemap,
          layers: [layer]
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-98.5795, 39.8282],
          zoom: 3,
          popup: {
            autoOpenEnabled: false
          }
        });

        const legend = new Legend({ view: view });
        // Expand widget to expand and contract the legend widget
        const legendExpand = new Expand({
          expandTooltip: "Show Legend",
          expanded: false,
          view: view,
          content: legend
        });

        // Add widgets to the view
        view.ui.add(document.getElementById("gridDiv"), "bottom-left");
        view.ui.add(legendExpand, "top-right");

        // Initialize variables
        let highlight, grid;

        // call clearMap method when clear is clicked
        const clearbutton = document.getElementById("clearButton");
        clearbutton.addEventListener("click", clearMap);

        layer.load().then(function () {
          return (g = new Grid());
        });

        view.on("click", function (event) {
          clearMap();
          queryFeatures(event);
        });

        function queryFeatures(screenPoint) {
          const point = view.toMap(screenPoint);

          // Query the for the feature ids where the user clicked
          layer
            .queryObjectIds({
              geometry: point,
              spatialRelationship: "intersects",
              returnGeometry: false,
              outFields: ["*"]
            })

            .then(function (objectIds) {
              if (!objectIds.length) {
                return;
              }

              // Highlight the area returned from the first query
              view.whenLayerView(layer).then(function (layerView) {
                if (highlight) {
                  highlight.remove();
                }
                highlight = layerView.highlight(objectIds);
              });

              // Query the for the related features for the features ids found
              return layer.queryRelatedFeatures({
                outFields: ["NAME", "SUM_POPULATION"],
                relationshipId: layer.relationships[0].id,
                objectIds: objectIds
              });
            })

            .then(function (relatedFeatureSetByObjectId) {
              if (!relatedFeatureSetByObjectId) {
                return;
              }
              // Create a grid with the data
              Object.keys(relatedFeatureSetByObjectId).forEach(function (
                objectId
              ) {
                // get the attributes of the FeatureSet
                const relatedFeatureSet = relatedFeatureSetByObjectId[objectId];
                const rows = relatedFeatureSet.features.map(function (feature) {
                  return feature.attributes;
                });

                if (!rows.length) {
                  return;
                }

                // create a new div for the grid of related features
                // append to queryResults div inside of the gridDiv
                const gridDiv = document.createElement("div");
                const results = document.getElementById("queryResults");
                results.appendChild(gridDiv);

                // destroy current grid if exists
                if (grid) {
                  grid.destroy();
                }
                // create new grid to hold the results of the query
                grid = new Grid(
                  {
                    columns: Object.keys(rows[0]).map(function (fieldName) {
                      return {
                        label: fieldName,
                        field: fieldName,
                        sortable: true
                      };
                    })
                  },
                  gridDiv
                );

                // add the data to the grid
                grid.renderArray(rows);
              });
              clearbutton.style.display = "inline";
            })
            .catch(function (error) {
              console.error(error);
            });
        }

        function clearMap() {
          if (highlight) {
            highlight.remove();
          }
          if (grid) {
            grid.destroy();
          }
          clearbutton.style.display = "none";
        }
      });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;

  &amp;lt;body&amp;gt;
    &amp;lt;div id="gridDiv" class="esri-widget"&amp;gt;
      &amp;lt;h2&amp;gt;US Cities&amp;lt;/h2&amp;gt;
      &amp;lt;p&amp;gt;
        Click on a hexagon in the map to view the US cities located in that
        area.
      &amp;lt;/p&amp;gt;
      &amp;lt;div id="queryResults"&amp;gt;&amp;lt;/div&amp;gt;
      &amp;lt;button id="clearButton" class="esri-widget"&amp;gt;Clear Query&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 21:43:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-field-aliases-inside-query-widget/m-p/1210582#M78620</guid>
      <dc:creator>Rice_GIS</dc:creator>
      <dc:date>2022-09-07T21:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Field Aliases inside Query Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-field-aliases-inside-query-widget/m-p/1210601#M78623</link>
      <description>&lt;P&gt;I suppose there are many ways, but here's a simple example.&amp;nbsp; You would replace lines 181-192 (where the Grid is created) with the following, which uses a simple field name to field alias map:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;grid = new Grid(
	{
		columns: Object.keys(rows[0]).map(function (fieldName) {
			var fieldAliases = {
				"NAME": "City",
				"SUM_POPULATION": "Sum Population"
			};

			return {
				label: fieldAliases[fieldName] || fieldName,
				field: fieldName,
				sortable: true
			};
		})
	},
	gridDiv
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 23:11:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-field-aliases-inside-query-widget/m-p/1210601#M78623</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2022-09-07T23:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Field Aliases inside Query Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-field-aliases-inside-query-widget/m-p/1210750#M78634</link>
      <description>&lt;P&gt;Worked Great! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 13:51:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/custom-field-aliases-inside-query-widget/m-p/1210750#M78634</guid>
      <dc:creator>Rice_GIS</dc:creator>
      <dc:date>2022-09-08T13:51:27Z</dc:date>
    </item>
  </channel>
</rss>

