
# Data type

RealGrid DataProvider's DataField can be one of four data types.
These are Text, Number, Boolean, and Datetime, and they are declared as RealGrids.DataType constants.

```js
var DataType = {
     TEXT: "text",
     NUMBER: "number", // or "numeric"
     BOOLEAN: "boolean", // or "bool"
     DATETIME: "datetime"
};
```

In the Local DataProvider (data is stored in RealGrid memory. The current RealGrid DataProvider is Local DataProvider), values are changed and stored according to the data type of each field.

---

#### 1). Text

It is a string. Strings passed to RealGrid DataProvider through fillJsonData() or setRows() must be encoded in UTF-8.
In the Local DataProvider, values that are not <mark>strings are converted to strings and stored in the DataProvider. undefined is stored as undefined.</mark>

---

#### 2). Number

IEEE-754 double precision floating point value. Same as Number in Javascript. There is no separate integer data type.
In the Local DataProvider, <mark>Values that are not Number are converted to Number and stored in the DataProvider. undefined is stored as undefined.</mark>

---

#### 3). Boolean

It is stored as one of two values: false or true. In other words, when external data is stored in a Boolean field using loadData() or setRows(), the original value that is not a <mark>Boolean is not preserved and is converted to true/false. undefined is stored as undefined.</mark> The values below are converted to false, and the remaining values are converted to true.

```
0 Javascript number 0
NaN Javascript NaN
"" empty string
null Javascript null
```

They are stored in the DataProvider as one of two values: false/true, but compatibility with strings becomes necessary at various points during grid use.
The cases where compatibility between Boolean field values and string values must be considered are as follows.

---

### Text -> DataProvider

When adding rows to the DataProvider using fillJsonData() or setRows(), etc., if you want to store a non-Boolean value in a Boolean field, use the booleanFormat property of the DataProvider or DataField.

```
dataProvider.setOptions({
     booleanFormat: "false,f:true:0"
});
dataProvider.setFields([{
     booleanFormat: "false,f:true:0"
},
...}]);
```

The booleanFormat property value is formatted as "false,f:true:0".
It is separated by a colon (:). The first section specifies one or more values to be interpreted as false, separated by commas, and the second section specifies one or more values to be interpreted as true, also separated by commas.
In the third bar, enter 1 if case is to be interpreted as case sensitive, or 0 if interpreted without distinction. If not specified or an invalid value is specified, it is case sensitive.
If both DataProvider and DataField are specified, those specified in DataField are followed.
When a property value is specified and it is not a Boolean value, if there is a corresponding value in the list of two property values, its setting is followed, and values not in the property list are stored according to the Boolean conversion rules described above. The original values are not saved.
In other words, in any situation, the original Text value is stored only as true/false in the Bool field. undefined values are stored as undefined.

---

#### Cell Renderer

Cell renderers display the value of a Boolean field based on the value of the booleanFormat property. If booleanFormat is not set, they will display "false" and "true" respectively. undefined is displayed as an empty string.

```
grid.setColumns([{
     booleanFormat: "Lie;Truth",
     ...
}, {
...}]);
```

The booleanFormat style property specifies false/true/undefined values by separating them with a semicolon (;) or colon (:), such as "Lie;True;Lie."

---

#### Cell Editor

Cell editors that input text can specify the booleanFormat property to display the value of a Boolean field as text and save the entered text value as a Boolean value.

```
grid.setColumns([{
     editor: {
         booleanFormat: "false,f:true:0",
         emptyValue: false // default value is undefined
         ...
     }
}, {
...}]);
```

The cell editor's booleanFormat property specifies the format as "false,f:true:0".
They are separated by a colon (:). The first section separates the values to be interpreted as false with a comma, and the second section specifies the values to be interpreted as true.
In the third bar, enter 1 if case is to be interpreted as case sensitive, or 0 if interpreted without distinction.
If not specified or an invalid value is specified, it is case sensitive.
Additionally, the first value in the false and true list will be the value displayed in the editor when editing begins.
If booleanFormat is not specified, "false,f,0:true,t,1:0" is used as the default format.
Specifies the value to be converted when entering an empty string in the emptyValue property. If not specified, it is stored as undefined.

---

#### 4). Datetime

The values of the Datetime field are stored in the DataProvider as a Date object created by the Flash player.
undefined is stored as undefined. However, RealGrid users mainly use values converted to Text or values converted to Javascript Date objects through Javascript functions.
Additionally, since it is entered using a datetime editor, etc., the date value is handled regardless of the internal implementation method.

---

#### 4.1). load

When a Datetime type value is passed as a string through fillJsonData(), or when the value of a Date field is passed as a string in JavaScript using the setRows() function, etc., the string can be recognized by RealGrid as a Datetime type value as shown below. It must be organized in several formats. This type of format can be specified in the datetimeFormat property and related properties of DataProvider or DataField. If both DataProvider and DataField are set, the one specified in DataField takes precedence.

```
dataProvider.setOptions({
     datetimeFormat: "yyyy/MM/dd",
     amText: "AM",
     pmText: "PM",
     baseYear: 2000
});
dataProvider.setFields([{
     datetimeFormat: "yyyy/MM/dd",
     amText: "am",
     pmText: "pm",
     baseYear: 2000
},
...}]
```

---

#### custom

The datetimeFormat property of DataProvider or DataField is specified as a pattern such as "yyyy/MM/dd".
Additionally, DataProvider and DataField have baseYear, amText, and pmText properties needed to interpret custom formats.
baseYear is the base year if the year value is less than 100. The default is 2000.
Specify the AM/PM separator for amText and pmText, respectively. This value must be specified to interpret AM/PM delimiters contained in the string.
The string includes an AM/PM separator, and if you do not specify it in the format, the time value will not be read. The default is "AM", "PM".
If the datetimeFormat property is not specified in DataField, the datetimeFormat, amText, pmText, and baseYear property values specified in DataProvider are used.
If datetimeFormat is specified in DataField, but amText, pmText, and baseYear are not specified, the value specified in DataProvider is used.
The default values specified in the DataProvider are "yyyy/MM/dd HH:mm:ss", "AM", "PM", 2000 respectively. String patterns that can be interpreted in custom format are as follows.
Be careful as it is case sensitive. Additionally, if the string is displayed in a format different from the specified pattern or is outside the range, it may be interpreted as a value different from what was intended.

---


|||
|- |- |
|**Year (y)**| Lowercase letters yy, yyyy Specify one of two options. The year must be two or four digits, such as 14, 2104. Must be a value between 0 and 9999.|
|**Month (M)**| Uppercase MM: Must be two digits, such as 01 or 12, and must be a value between 1 and 12.|
||Capital letter M: The leading 0 can be omitted, such as 1 and 12. In this case, the separator must be included.|
||(currently only RealGrid+)|
|**Day (d)**| Lowercase dd: The date must be two digits, such as 01 or 22, and a value between 1 and 31. |
||Lowercase d: The leading 0 can be omitted, such as 1, 22. In this case, the separator must be included.|
|| (currently only RealGrid+) |
|**AM/PM (a)**| Specified with a lowercase a. The AM/PM separator must be the same as the value specified in the amText and pmText properties. |
|**Time (H)**| Uppercase HH: Must be two digits, such as 00, 13, and a value between 0 and 23. 24 is interpreted as 00:00 the next day.|
||Capital letter H: The leading 0 can be omitted, such as 0, 13. In this case, the delimiter must be included. 24 is interpreted as 00:00 the next day. |
|| (currently only RealGrid+) |
|**Time (h)**| Lowercase hh: Must be two digits, such as 00, 10. |
||Must be a value between 1 and 12. If the value of a is amText, 12 is interpreted as 0 o'clock. In the case of pmText, it is interpreted as 12 o'clock (noon). |
||The leading 0 can be omitted, such as lowercase h: 0, 10. |
||In this case, the separator must be included.a If the value is amText, 12 is interpreted as 0 o'clock. In the case of pmText, it is interpreted as 12 o'clock (noon). |
|| (currently only RealGrid+) |
|**Minutes (m)**| It must be two digits, such as lowercase mm:00, 33. Must be a value between 0 and 59. |
||The leading 0 can be omitted, such as lowercase m: 0, 33. In this case, the delimiter must be included. Must be a value between 0 and 59. |
|| (currently only RealGrid+) |
|**Seconds (s)**| Lowercase ss: Must be two digits, such as 00, 22. Must be a value between 0 and 59. |
||The leading 0 can be omitted, such as lowercase s: 0, 22. In this case, the delimiter must be included. Must be a value between 0 and 59. |
|| (currently only RealGrid+) |
|**Milliseconds (S)**| Specified with uppercase SSS. Milliseconds must be three digits, such as 000, 122. Must be a value between 0 and 999.
|**Separators**| There are year separators "/", ".", "-" and time separator ":". |
||Blanks may also be included. The delimiter only plays a positional role and can be interpreted even if it does not match that of the string. |
||In other words, even though "/" is specified in the pattern, it is interpreted even if there is "-" in that position in the string. |

Even if the number of string patterns is less than the number of patterns specified in the format, they are interpreted as much as possible. The following examples are possible.

|||
|- |- |
|**yyyy/MM/dd a**|"2014/01/12 AM 13:22:33"|
|**HH:mm:ss**|"2014.11.22"|
|**yyyy/MM/dd**|"2014.11.22"|
||"2014/12"|


---

#### iso

Specify the datetimeFormat property as "iso".
Interprets values expressed in the ISO 8601 standard date/time format below.

YYYY-MM-DDTHH:NN:SSTZD

If a time part is present, the middle "T" must be present.
The "TZD" location must contain a time zone.
If standard time is used, the local time zone value must be specified with the letter "Z"; otherwise, the local time zone value must be specified, such as "+09:00" or "-02:00".
According to the ISO standard, a time zone must exist, but in RealGrid, if it is not specified, it is interpreted as the local time zone value.
Additionally, it is interpreted even if there is no time part or only part of the date exists. If the year is two digits, the year 1900 is added and interpreted.
Strings that can be interpreted in "iso" format are as follows.

```
"2014/12/12T21:22:33Z"
"2014/12/12T21:22:33+09:00"
"2014/12/12T21:22"
"2014/12/12"
"2014/12"
```

---

#### flash

Specify the datetimeFormat property as "flash".
This is a format natively supported by the Flash platform. . If the year is two digits, the year 1900 is added and interpreted.
An example that can be interpreted is as follows.

```
"2014/12/12T21:22:33Z"
"2014/12/12T21:22:33+09:00"
"2014/12/12T21:22"
"2014/12/12"
"2014/12"
```

If possible, this format should be followed. Especially when loading large amounts of data of more than 100,000 items, this format parses several times faster than "iso" or custom formats.

```
"Wed Jan 1 11:22:33 GMT+0900 2014"
"Wed Jan 1 2014 11:22:33 GMT+0900"
"Wed Jan 1 2014"
"01/01/2014"
"01/2014"
"2014/01/01 11:22:33 GMT+0900"
"2014/01/01 11:22:33"
"2014/01/01"
```

---

#### 4.2) rendering
Cell renderers that display values from Datetime fields use datetimeFormat style values.

```
grid.setColumns([{
     datetimeFormat: "yyyy.MM.dd a HH:mm:ss;am,pm",
     ...
}, {
...}]);
```

The datetimeFormat style can consist of the following patterns:
If no style value is specified, the "yyyy/MM/dd" format is used by default.
If an older version of the dateFormat style property is specified, the cell renderer will use that format, but the dateFormat style property is being deprecated.
Get rid of the dateFormat style value and reset it to the datetimeFormat style value.
Patterns in this format are case sensitive, and the number of digits is significant.

---

|||
|- |- |
|**Year (y)**| yyyy = 2014, yy = 14|
|**Month (M)**| M = 1, MM = 11|
|**Day (d)**| d = 1, d d = 11, d d = 01|
|**AM/PM (a)**| AM, PM |
|**Hours (H: 0 ~ 23)**| H = 1, H = 11, HH = 01|
|**Hours (h: 1 ~ 12)**| h = 1, h = 11, hh = 01|
|**Minutes (m)**| m = 1, mm = 11, mm = 01|
|**Seconds (s)**| s = 1, ss = 11, ss = 01|
|**Milliseconds (S)**| S = 1, SS = 12 SSS = 123|
|**Separators (:, /, ., -)**| yyyy/MM/dd, yyyy.MM.dd, yyyy-MM-dd, HH:mm:ss.SSS|
|**Text**| Unless the text starts with a capital letter 'a' through 'z', it is displayed as text.|

---

#### 4.3) editing
A cell editor that inputs the value of a Datetime field also needs a format to convert the user's input into a Datetime value and display the Datetime value in the editor.
Specify the format below in the datetimeFormat property of the cell editor.

```
grid.setColumns([{
     editor: {
         datetimeFormat: "yyyy.MM.dd a HH:mm:ss;2000;am,pm",
         ...
     }
}, {
...}]);
```

It is separated by a semicolon (;). The first section specifies the date/time pattern, and the second section specifies the year to be automatically added when the year is entered in two digits or less.
The default is 2000. In the third measure, specify the AM/PM separators in order, separated by commas.
The following components can be specified in a date/time pattern. When entering, the number of digits is not important as long as the value is within the range.
In other words, if you set the pattern to "yy" and enter "2014", the year will be 2014.
However, when displaying in the editor at the start of editing, the number of digits is displayed.

---

|||
|- |- |
|Year (y)|yyyy = 2014, yy = 14|
||If you enter a value less than 100, it is interpreted by adding the base year specified in the second part of datetimeFormat.|
|Month (M)|M = 1, M = 11, MM = 01|
|day (d)|d = 1, d = 11, dd = 01|
|AM/PM separator (a)| The value specified in the third clause of datetimeFormat is used. |
||"am", "pm" are not case sensitive and are interpreted as am and pm respectively. |
||If am or pm is set, "H" and "h" will have a range from 1 to 12 when input. |
||If it is 12 o'clock and am, it is interpreted as 0 o'clock, and if it is 12 o'clock and pm, it is interpreted as 12 o'clock.|
|H: Hour (0 ~ 23)| H = 1, H = 11, HH = 01|
||When inputting, 24 is interpreted as 0. Any value over 24 is an error.|
|h: hour (1 to 12)| h = 1, h = 11, hh = 01|
||When inputting, it is interpreted the same as "H".|
|m: minute (0 to 59)| m = 1, m = 11, mm = 01|
||When inputting, 60 is interpreted as 0. Any value over 60 is an error.|
|s: seconds (0 to 59)| s = 1, s = 11, ss = 01|
||When inputting, 60 is interpreted as 0. Any value over 60 is an error.|
|Separator|The separator can be specified as one of five characters. |
|(./-:whitespace)|Consecutive whitespaces are interpreted as a single delimiter both in the format and in the input value.|
|Continuous value|If the format string is specified consecutively without a delimiter, such as "yyyyMMdd", one continuous number string among the input values is interpreted by comparing it with the format. |
||At this time, the input number string is separated and interpreted starting from the first token according to the number of digits of each token included in the format string.|
||"yyyyMMdd": "2014032" => 2014.03.02, "yyyyMMdd": "2014" => 2014.01.01, "yyyyMM": "20140505" => 2014.05.01|
||"yyyyMMdd": "2014.02.03" => 2014.01.01, "yyyyMMdd.MM.dd": "201401.02.03" => 2014.02.03|


If you enter an error value, the input will be ignored.