Types are not labels
Every network inventory anybody has ever maintained has the same bug in it. The addresses sort wrong, or the uptimes sort wrong, or the transfer volumes sort as text because one of them is “1.2 TB” and another is “980 GB”. Somebody has usually fixed it once, in that one screen, with a comparator function pasted next to the column, and it is wrong again in the export.
The grid above is fifty thousand devices, and it lands sorted on the Address column. Scroll it and read the first octet down.
One word, five jobs
The Address column is declared like this:
{ field: 'address', title: 'Address', type: 'ipv4', layout: { width: 150 } }
type: 'ipv4' is not a label saying what the column contains. It decides five
things at once.
Storage. The cell is held as a thirty-two bit integer, not as a string. 10.0.0.5 is one number in a typed array rather than seven characters.
Comparison. Sorting compares those integers, which is why the ordering is right at 128.0.0.0 and everywhere else. We sorted the fifty thousand addresses above and walked every adjacent pair against the integer value: zero pairs out of order.
Parsing. Typing an address into a cell produces the integer, and something that is not an address is rejected rather than stored as text that will sort oddly later.
Formatting. The integer reads as four octets again on the way out, so what is stored and what is shown are two different things and only one of them has to be sortable.
The editor. The cell opens an address editor rather than a text box, because the type names one.
Then the export. Each type also carries the spreadsheet format it should land in: an address exports as text, so 10.0.0.5 is still 10.0.0.5 in the sheet rather than a date or a truncated decimal; a duration exports as elapsed hours; a byte count exports as a number with a unit suffix. That is the part people usually find out about on a Friday.
The column beside it is the proof
Uptime and “Uptime, as text” hold the same fifty thousand uptimes. One is
type: 'duration', which stores milliseconds and sorts numerically. The other
is the string a person would have typed, “729d 1h” or “2m”, stored as text.
Sort the duration column and the order is the true order: we checked every adjacent pair against the stored milliseconds and found zero out of order. Sort the text column and the order looks plausible and is not. Against the same true millisecond order, that column has 20,515 adjacent pairs the wrong way round out of 49,999. It puts every “1d 0h” above every “2m”, because “1” sorts before “2” and always will.
Both columns are readable. Only one of them is correct, and the difference is one word in the configuration.
Transferred and Disk free are type: 'bytes', so the values are stored as bytes
and shown at whatever unit each row deserves. Subnet is type: 'cidr'. Poll
time is another duration, in the same column list, sorting on the same scale
without anybody writing a comparator.
Twenty of them, and none of them configured
Twenty extended types are registered by default. Beyond the ordinary text, number, date and boolean, that is time, datetime, duration, ipv4, ipv6, cidr, json, secret, bytes, megabytes, gigabytes, bitrate, gigabits, and hex, binary and octal at several widths. We counted them off the registry rather than the documentation.
There is nothing to install and nothing to register. No dataTypes block
appears in the configuration above, because none of these needed one. If you do
need something the grid does not ship, a type is a small object with a
comparator, a parser and a formatter, and registering it is a map entry.
The argument here is not that any single one of these is hard to write. It is that you will write the address comparator, and then the duration comparator, and then the byte parser, and then the export format for all three, and each of them will be right in the screen where you wrote it and absent everywhere else. This is the same work done once, underneath, where the sort, the filter, the editor and the export all reach the same answer.
Sort the two uptime columns above one after the other and the point takes about four seconds.