
# subtypes

As described in *Data Type*, RealGrid DataProvider's DataField can be one of four data types.
However, it is common for primitive data types to be used to a limited extent in work environments.
RealGrid supports the _Subtype_ property per DataField to support some of these requirements.
*Subtype* can be specified when adding a data field, and the _"subtype"_ indicator and _"set"_ and _"min"/"max"_ qualifiers can be used.
However, Subtype is not the data type of the data field, but only serves to fit the value of the field into the specified range when it is stored in the DataProvider.
In other words, existing data saved at the time when subtype application is canceled or data saved by applying another subtype are not adjusted to the new subtype.
Of course, it is possible to have the UI or other functions operate according to the specified Subtype in addition to the role of the storage range.

---

#### 1). subtype indicator

When specifying a data field, it can be set as the "subType" property. The values that can be set for each basic data type are as follows.

|||
|- |- |
|**Text**|_"char"_ - Stored as a string of limited length with a _"length"_ property greater than 0. |
||If "length" is specified as 0 or less, it is the same as the basic data type "text".|
|||
|**Number**|_"unum"_ - Stored as a number greater than or equal to 0.|
||_"int"_ - Stored as an integer value. |
||Stored in the same way as <mark>i = v >= 0 ? Math.floor(v) : Math.ceil(v)</mark>.|
||In other words, if it is 1.1, it is stored as 1, and if it is -1.1, it is stored as -1.|
||_"uint"_ - Stored as an integer value greater than or equal to 0.|
||Stored in the following way <mark>i = Math.floor(v);</mark>.|
|||
|**Datetime**|_"date"_ - The date value is saved with the time part removed.|

```
"fields": [{
     "fieldName": "ItemId",
     "dataType": "number",
     "subType": "unum"
},{
     "fieldName": "ItemName",
     "dataType": "text",
     "subType": "char",
     "length": 100
},{
...
}];
```

---

#### 2). minimum/maximum

When adding a DataField, you can specify the _"min"_ or _"minimum"_ and _"max"_ or _"maximum"_ properties to set the range in which the value is stored.
_Values beyond the boundary are stored as boundary values._ That is, values less than min are stored as min, and values greater than max are stored as max.
You can specify either the minimum or minimum value, and if you specify the maximum value less than the minimum value, this range will be ignored.
These properties can be specified for _Number and Datetime_ data types.
When specifying this property for a Datetime field, specify it as a string that matches the field's datatimeFormat or, if not specified for the field, the datetimeFormat set in the DataProvider.

```
"fields": [{
    "fieldName": "Price",
    "dataType": "number",
    "min": 100,
    "max": 200
    ...
```

---

#### 3). set

You can specify the _"set"_ array property value on DataFields of data types other than the _Boolean_ data type so that if the value is not included in the array, it is stored as *undefined*.

```
"fields": [{
    "fieldName": "State",
    "set": ["ab", "cd", ...],
    ...
```

---

#### 4). caution

As pointed out above, RealGrid Subtype is a type of constraint that adjusts the input value to a value within the range without causing an error.
You can disable or re-enable the subtype function with the _subtypeEnabled_ property of DataProvider.
Additionally, if subtypeEnabled is set to true in the DataProvider, subtypeEnabled for each data field can be activated/deactivated through the property.

The Subtype setting is applied just before the requested field value is stored in the _DataProvider, such as when adding/changing rows._