import NumberFieldFormat from "@arcgis/core/layers/support/NumberFieldFormat.js";
const NumberFieldFormat = await $arcgis.import("@arcgis/core/layers/support/NumberFieldFormat.js");
@arcgis/core/layers/support/NumberFieldFormat
The NumberFieldFormat
class defines the formatting options for numeric field types. It is used in the FieldConfiguration class to define the display format of fields in a FeatureLayer. It is also used in the FieldInfo class to define the display format of fields content in a PopupTemplate.
It applies to both the map's popup and any components/widgets that display the field.
Breaking change
Numeric fields with decimal values are now automatically formatted with a limit on decimal places. For example, a value such as 1.234566788
would display with all available decimal places in the FeatureTable. Now, if no field configurations are defined, components automatically limit the display to three decimal places (1.234
). To customize this behavior, define field configurations on your layer.
Numeric Format Mappings
The following tables show equivalencies between the legacy FieldInfoFormat.places
and FieldInfoFormat.digitSeparator
values and NumberFieldFormat
properties. The examples shown are for the en-US
locale. Note that the actual display will vary based on the locale of the user.
Integer Field Types
Legacy | NumberFieldFormat equivalency | Example (en-US) |
---|---|---|
digitSeparator = true |
useGrouping = "always" |
1,234,567 |
digitSeparator = false |
useGrouping = "never" |
1234567 |
Floating-point field types
Legacy | NumberFieldFormat equivalency | Example: (en-US) Input | NumberFieldFormat output |
---|---|---|---|
digitSeparator = true , places = 4 |
useGrouping = "always" , minimumFractionDigits = 4 , maximumFractionDigits = 4 |
1,234.5678 | 1,234.5678 |
digitSeparator = false , places = 4 |
useGrouping = "never" , minimumFractionDigits = 4 , maximumFractionDigits = 4 |
1234.5678 | 1234.5678 |
digitSeparator = false , places = 3 |
useGrouping = "never" , minimumFractionDigits = 2 , maximumFractionDigits = 3 |
1234.323443 | 1234.323 |
digitSeparator = true , places = 2 |
useGrouping = "auto" , minimumFractionDigits = 3 , maximumFractionDigits = 3 |
1,234.323443 | 1,234.323 |
// Create a number field format
const numberFieldFormat = new NumberFieldFormat ({
minimumFractionDigits: 1,
maximumFractionDigits: 3,
useGrouping: "never"
});
// Create a field configuration object containing the number format
const numberFieldConfiguration = new FieldConfiguration ({
name: "voterCount", // name of the field in the service
fieldFormat: numberFieldFormat,
alias: "Voter Count"
});
// Create a feature layer and pass in the field configurations
const featureLayer = new FeatureLayer ({
url: "url to feature layer",
outFields: ["*"],
fieldConfigurations: [numberFieldConfiguration] // add as many field configurations as needed
});
Constructors
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
The name of the class. | Accessor | ||
The maximum number of decimal places to display. | NumberFieldFormat | ||
The minimum number of decimal places to display. | NumberFieldFormat | ||
The formatting style to use. | NumberFieldFormat | ||
The type of field format. | NumberFieldFormat | ||
Indicates whether to use grouping separators, such as thousands separators. | NumberFieldFormat |
Property Details
-
maximumFractionDigits
maximumFractionDigits Number
-
The maximum number of decimal places to display. If the number has more decimal places, it will be rounded to the nearest value with the specified number of decimal places. For example, if
maximumFractionDigits
is set to2
, the number3.456
will be displayed as3.46
.- See also
-
minimumFractionDigits
minimumFractionDigits Number
-
The minimum number of decimal places to display. If the number has fewer decimal places, it will be padded with trailing zeros. If the number has more decimal places, it will be rounded to the nearest value with the specified number of decimal places. For example, if
minimumFractionDigits
is set to2
, the number3.1
will be displayed as3.10
and the number3.456
will be displayed as3.46
.- See also
-
style
style Stringreadonly
-
The formatting style to use. Support is currently limited to
decimal
style.For NumberFieldFormat the style is always "decimal".
- Default Value:decimal
- See also
-
type
type Stringreadonly
-
The type of field format.
For NumberFieldFormat the type is always "number".
-
useGrouping
useGrouping String
-
Indicates whether to use grouping separators, such as thousands separators. For example, if
useGrouping
is set toalways
, the number1234567
will be displayed as1,234,567
. If set tonever
, the number will be displayed as1234567
.auto
is the default value and uses grouping separators based on the locale and the number of digits.Possible Values:"always" |"auto" |"never"
- Default Value:auto
- See also
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
this | Creates a deep clone of this object. | NumberFieldFormat | |
Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. | NumberFieldFormat | ||
Returns true if a named group of handles exist. | Accessor | ||
Removes a group of handles owned by the object. | Accessor | ||
Converts an instance of this class to its ArcGIS portal JSON representation. | NumberFieldFormat |
Method Details
-
Inherited from Accessor
-
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
Creates a deep clone of this object. Any properties that store values by reference will be assigned copies of the referenced values on the cloned instance.
ReturnsType Description this A deep clone of the class instance that invoked this method.
-
Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input
json
parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.Parameterjson ObjectA JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.
Returns
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from Accessor -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
Inherited from Accessor
-
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
-
toJSON
toJSON(){Object}
-
Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.
ReturnsType Description Object The ArcGIS portal JSON representation of an instance of this class.