Column Type
Properties related to column types.
defaultColumnTypeName
- Type:
string
- Default: First available type to not have validation -> First available type -> "Text"
Name for the default column type.
Example
- Sample code
- Full code
<active-table defaultColumnTypeName="Label"></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
defaultColumnTypeName="Label"
data='[
["Planet", "Diameter", "Mass", "Moons", "Density"],
["Earth", 12756, 5.97, 1, 5514],
["Mars", 6792, 0.642, 2, 3934],
["Jupiter", 142984, 1898, 79, 1326],
["Saturn", 120536, 568, 82, 687],
["Neptune", 49528, 102, 14, 1638]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
availableDefaultColumnTypes
- Type:
DEFAULT_COLUMN_TYPES[]
- Default: ["Text", "Number", "Currency", "Date d-m-y", "Date m-d-y", "Checkbox", "Select", "Label"]
Used to overwrite the available default column types. If array is set to empty ([]) and there are no customColumnTypes
, the default type
will be automatically set to "Text".
Example
- Sample code
- Full code
<active-table availableDefaultColumnTypes='["Number"]'></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
availableDefaultColumnTypes='["Number"]'
data='[
["Planet", "Diameter", "Mass", "Moons", "Density"],
["1", 12756, 5.97, 1, 5514],
["2", 6792, 0.642, 2, 3934],
["3", 142984, 1898, 79, 1326],
["4", 120536, 568, 82, 687],
["5", 49528, 102, 14, 1638]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
customColumnTypes
- Type:
ColumnType[]
- Default: []
An array of custom column types which are automatically appended to the availableDefaultColumnTypes
types array.
Example
- Sample code
- Full code
<active-table
customColumnTypes='[{
"name": "Custom type",
"select": {
"options": ["Pass", "Fail"],
"canAddMoreOptions": false
},
"iconSettings": {
"reusableIconName": "select"
}}]'
availableDefaultColumnTypes="[]"
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[{
"name": "Custom type",
"select": {
"options": ["Pass", "Fail"],
"canAddMoreOptions": false
},
"iconSettings": {
"reusableIconName": "select"
}}]'
availableDefaultColumnTypes="[]"
data='[
["Category 1", "Category 2", "Category 3", "Category 4", "Category 5"],
["Pass", "Pass", "Fail", "Fail", "Fail"],
["Fail", "Pass", "Pass", "Fail", "Fail"],
["Fail", "Pass", "Pass", "Pass", "Fail"],
["Pass", "Fail", "Fail", "Pass", "Pass"],
["Pass", "Fail", "Fail", "Fail", "Fail"]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
Types
Shared object property types related to column types:
ColumnType
Type: {
name: string
,
textValidation?: TextValidation
,
customTextProcessing?: CustomTextProcessing
,
sorting?: Sorting
,
iconSettings?: IconSettings
,
select?: boolean|CellDropdown<SelectOptions>
,
label?: boolean|CellDropdown<LabelOptions>
,
calendar?: Calendar
,
checkbox?: Checkbox
}Default: {
sorting: in the ASCII character order ("Text" type),
dropdownIconSettings: using "Text" type icon
}
Details for creating a column type.
If textValidation
and customTextProcessing
are both provided, customTextProcessing
will be executed first.
The select
, label
, calendar
and checkbox
properties facilitate unique features and if
more than one of these is provided - only the first one will be used in that order.
TextValidation
- Type: {
func: (cellText: string) => boolean
,
setTextToDefaultOnFail?: boolean
,
failedStyle?: NoDimensionCSSStyle
,
} - Default: { setTextToDefaultOnFail: true }
Used to enforce cell text validation. This operates only in the data cells and not the header.
The func
property takes a function that will be called when the text is initially placed in the cell and when
it changes. The function must return true if the text is correct or false if it is incorrect.
setTextToDefaultOnFail
will reset the cell text to value defined inside defaultText
if the function returns false.
failedStyle
is used to change the cell styling if the function returns false.
Example validation for if number is higher than 20
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom type",
"textValidation": {
"func": "(cellText) => Number(cellText) > 20",
"setTextToDefaultOnFail":false,
"failedStyle":{"color":"red"}
}}]'
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom type",
"textValidation": {
"func": "(cellText) => Number(cellText) > 20",
"setTextToDefaultOnFail":false,
"failedStyle":{"color":"red"}
}}]'
defaultColumnTypeName="Custom type"
data='[
["Gravity", "Diameter", "Mass", "Moons", "Density"],
[9.8, 12756, 5.97, 1, 5514],
[3.7, 6792, 0.642, 2, 3934],
[23.1, 142984, 1898, 79, 1326],
[9, 120536, 568, 82, 687],
[11, 49528, 102, 14, 1638]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
CustomTextProcessing
- Type: {
changeTextFunc?: (cellText: string, rowIndex: number) => string|number
,
changeStyleFunc?: (cellText: string, rowIndex: number) => NoDimensionCSSStyle
,
}
Augments cell after its text is changed. changeTextFunc
is a function that processes cell text and
returns same/new text depending on its contents. changeStyleFunc
is a function that processes cell text and
returns a styling object for the cell depenging on its contents.
Example processing for currency: 20 (red) < 100 (yellow) < more (green)
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom type",
"customTextProcessing": {
"changeTextFunc": "(cellText) => `$${Number(cellText.replace(/[^0-9.-]+/g,\"\"))}`",
"changeStyleFunc": "(cellText) => {
const moneyNumber = Number(cellText.replace(/[^0-9.-]+/g,\"\"));
if (moneyNumber < 20) return {backgroundColor: `#ff3232`};
if (moneyNumber < 100) return {backgroundColor: `#ffff00`};
return {backgroundColor: `#00ac00`};
}"
}}]'
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom type",
"customTextProcessing": {
"changeTextFunc": "(cellText) => `$${Number(cellText.replace(/[^0-9.-]+/g,\"\"))}`",
"changeStyleFunc": "(cellText) => {
const moneyNumber = Number(cellText.replace(/[^0-9.-]+/g,\"\"));
if (moneyNumber < 20) return {backgroundColor: `#ff3232`};
if (moneyNumber < 100) return {backgroundColor: `#ffff00`};
return {backgroundColor: `#00ac00`};
}"
}}]'
defaultColumnTypeName="Custom type"
data='[
["Gravity", "Diameter", "Mass", "Moons", "Density"],
[9.8, 12756, 5.97, 1, 5514],
[3.7, 6792, 0.642, 2, 3934],
[23.1, 142984, 1898, 79, 1326],
[9, 120536, 568, 82, 687],
[11, 49528, 102, 14, 1638]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
Sorting
- Type: {
ascendingFunc: (cellText1: string, cellText2: string) => number
,
descendingFunc: (cellText1: string, cellText2: string) => number
,
}
Facilitates column cell sorting capabilities. The functions are executed using the standard JavaScript .sort method and are expected to return a negative value (< 0) if cellText1 is less than cellText2, zero (0) if both arguments are equal, or a positive value (> 0) if cellText1 is greater than cellText2.
Example sorting for numbers
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom type",
"sorting": {
"ascendingFunc": "(cellText1, cellText2) => Number(cellText1) - Number(cellText2)",
"descendingFunc": "(cellText1, cellText2) => Number(cellText2) - Number(cellText1)"
}}]'
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom type",
"sorting": {
"ascendingFunc": "(cellText1, cellText2) => Number(cellText1) - Number(cellText2)",
"descendingFunc": "(cellText1, cellText2) => Number(cellText2) - Number(cellText1)"
}}]'
defaultColumnTypeName="Custom type"
data='[
["Gravity", "Diameter", "Mass", "Moons", "Density"],
[9.8, 12756, 5.97, 1, 5514],
[3.7, 6792, 0.642, 2, 3934],
[23.1, 142984, 1898, 79, 1326],
[9, 120536, 568, 82, 687],
[11, 49528, 102, 14, 1638]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
IconSettings
- Type: {
reusableIconName?: DEFAULT_COLUMN_TYPES
,
svgString?: string
,
containerStyles?
: {
columnDropdown?: CSSStyle
,
headerCorrections?: CSSStyle
,
}}
Defines column type icon properties.
reusableIconName
allows the icon to reuse of the existing default type icons.
svgString
is the full svg element string containing all DOM tags. Make sure to escape the quotes - change " to \" (An easy way to do this is to
stringify it using JSON.stringify()). If the string is defined directly in HTML (attribute), you will need to escape the first less than (<) character by replacing it with <
.
containerStyles
allows the icon dimensions to be customised when displayed in the columnDropdown
and in the header. By default, the columnDropdown
dimension
properties are also used for the header however if they don't fit the headerCorrections
object can be used to change them.
Example triangle icon
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom type",
"iconSettings": {
"svgString": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"10\" width=\"16\"> <polygon points=\"9,1 3,15 15,15\" class=\"triangle\" /></svg>",
"containerStyles": {
"dropdown": {"marginLeft": "-2.5px", "marginRight": "4px", "marginTop": "2px"},
"headerCorrections": {"marginTop": "-1px", "marginLeft": "-2px"}
}}}]'
}'
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom type",
"iconSettings": {
"svgString": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"10\" width=\"16\"> <polygon points=\"9,1 3,15 15,15\" class=\"triangle\" /></svg>",
"containerStyles": {
"dropdown": {"marginLeft": "-2.5px", "marginRight": "4px", "marginTop": "2px"},
"headerCorrections": {"marginTop": "-1px", "marginLeft": "-2px"}
}}}]'
defaultColumnTypeName="Custom type"
data='[
["Gravity", "Diameter", "Mass", "Moons", "Density"],
[9.8, 12756, 5.97, 1, 5514],
[3.7, 6792, 0.642, 2, 3934],
[23.1, 142984, 1898, 79, 1326],
[9, 120536, 568, 82, 687],
[11, 49528, 102, 14, 1638]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
Make sure the svg tag contains the xmlns="http://www.w3.org/2000/svg" and xmlns:xlink="http://www.w3.org/1999/xlink" attributes. The backslash \ syntax is only used when
setting customColumnTypes
as an attribute (full string) to escape its quotes and is not needed when assigned as a property.
CellDropdown
- Type: {
dropdownStyle?: CellDropdownStyle
,
optionStyle?: {textColor: string}
,
options?: SelectOptions|LabelOptions
,
canAddMoreOptions?: boolean
} - Default: { canAddMoreOptions: true or if options property is set then false }
Dropdown customization properties for select
and label
properties in the ColumnType
object.
dropdownStyle
and optionStyle
are used to apply specific dropdown styling aspects.
options
property defines custom options within the dropdown and uses the SelectOptions
type to define individual options when
used for a select
dropdown and LabelOptions
if used for label
.
canAddMoreOptions
controls whether new options can be added into the dropdown. If false then column cell text that
is not in the options array is automatically removed.
CellDropdownStyle
- Type: {
width?: string
,
paddingTop?: string
,
paddingBottom?: string
,
marginTop?: string
,
marginLeft?: string
,
textAlign?: string
,
border?: string
,
}
Styling properties for the select and label dropdowns.
SelectOptions
- Type:
string[]
Example for Select
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom select type",
"select": {
"dropdownStyle": {"border": "0.5px solid #00000066"},
"optionStyle": {"textColor": "#606060"},
"options": ["Elephant", "Tiger", "Giraffe"],
"canAddMoreOptions": false
}}]'
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom select type",
"select": {
"dropdownStyle": {"border": "0.5px solid #00000066"},
"optionStyle": {"textColor": "#606060"},
"options": ["Elephant", "Tiger", "Giraffe"],
"canAddMoreOptions": false
}}]'
defaultColumnTypeName="Custom select type"
data='[
["Animal 1", "Animal 2", "Animal 3", "Animal 4", "Animal 5"],
["Elephant", "Giraffe", "Elephant", "Giraffe", "Tiger"],
["Tiger", "Elephant", "Tiger", "Tiger", "Giraffe"],
["Giraffe", "Tiger", "Invalid animal", "Elephant", "Invalid animal"],
["Invalid animal", "Tiger", "Giraffe", "Invalid animal", "Tiger"]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
LabelOptions
- Type:
{text: string; backgroundColor?: string}[]
- Default: if backgroundColor is not provided then it is set to a random color
Example for Label
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom label type",
"label": {
"options": [{"text":"Elephant", "backgroundColor": "#4ddd3878"}, {"text":"Tiger", "backgroundColor": "#ff606082"}, {"text":"Giraffe", "backgroundColor": "#ff940f8f"}],
"canAddMoreOptions": true
}}]'
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom label type",
"label": {
"options": [{"text":"Elephant", "backgroundColor": "#4ddd3878"}, {"text":"Tiger", "backgroundColor": "#ff606082"}, {"text":"Giraffe", "backgroundColor": "#ff940f8f"}],
"canAddMoreOptions": true
}}]'
defaultColumnTypeName="Custom label type"
data='[
["Animal 1", "Animal 2", "Animal 3", "Animal 4", "Animal 5"],
["Elephant", "Giraffe", "Elephant", "Giraffe", "Tiger"],
["Tiger", "Elephant", "Tiger", "Tiger", "Giraffe"],
["Giraffe", "Tiger", "Elephant", "Elephant", "Kangaroo"],
["Goose", "Elephant", "Giraffe", "Whale", "Tiger"]]'
tableStyle='{"width":"100%", "boxShadow": "rgb(172 172 172 / 17%) 0px 0.5px 1px 0px", "borderRadius":"2px"}'
tableStyle='{"borderRadius":"2px"}'
></active-table>
Calendar
- Type: {
toYMDFunc: (cellText: string) => YMDFormat
,
fromYMDFunc: (YMD: YMDFormat) => string
}
Adds a hoverable calendar icon element to each data cell. When a cell is focused - a date picker overlay
is opened which the user can use to select the date they need.
The toYMDFunc
and fromYMDFunc
functions are strictly used for converting cell text into a format (YMDFormat
) the calendar API
accepts and back to the original format when a new date is chosen.
YMDFormat
- Type:
[string, string, string, string?, string?, string?, string?]
Date format used by the Date Picker
. The tuple contents translate to
year / month / day (as digits e.g. '2022') and optionally hours / minutes / seconds / milliseconds (not used by the picker but may be required
for a custom Calendar
type).
Example for custom d/m/y type
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom d/m/y type",
"calendar": {
"toYMDFunc": "(cellText) => { const integerArr = cellText.match(/\\d+/g); return [integerArr[2], integerArr[1], integerArr[0]]; }",
"fromYMDFunc": "(YMD) => { return [YMD[2], YMD[1], YMD[0]].join(`/`); }"
}}]'
defaultColumnTypeName="Custom d/m/y type"
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom d/m/y type",
"calendar": {
"toYMDFunc": "(cellText) => { const integerArr = cellText.match(/\\d+/g); return [integerArr[2], integerArr[1], integerArr[0]]; }",
"fromYMDFunc": "(YMD) => { return [YMD[2], YMD[1], YMD[0]].join(`/`); }"
}}]'
defaultColumnTypeName="Custom d/m/y type"
data='[
["Date 1", "Date 2", "Date 3", "Date 4"],
["3/2/2052", "4/2/1993", "6/12/2012", "2/2/2012"],
["18/12/0001", "2/4/1689", "16/2/2029", "1/02/2004"],
["12/8/1943", "24/2/1992", "16/12/2022", "17/3/2023"]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
The above code serves as an example and the toYMDFunc
function will break if cells do not adhere to the d/m/y format. It is advisable to
always analyze the incoming cellText
value format and return a default value if it is not what was expected. Additionally, it is highly
recommended to supplement calendar
with the use of textValidation
and customTextProcessing
properties to make sure cell text is always in the correct format.
Checkbox
- Type:
boolean
Replaces cell text with a checkbox.
This type automatically comes with a predefined customTextProcessing
property in the ColumnType
that
uses "", "0", "00" and "false" values to represent the checkbox as unchecked and all the other values as checked. You can overwite it
with your own changeTextFunc
function that would return a string of "true" when the checkbox should be checked and "false" when it should
be unchecked.
The onCellUpdate
and onDataUpdate
properties will return string "true" if the checkbox
is checked and "false" if unchecked.
Example
- Sample code
- Full code
<active-table
customColumnTypes='[
{
"name": "Custom checkbox type",
"checkbox": true
}]'
defaultColumnTypeName="Custom checkbox type"
></active-table>
<!-- This example is for Vanilla JS and should be tailored to your framework (see Examples) -->
<active-table
customColumnTypes='[
{
"name": "Custom checkbox type",
"checkbox": true
}]'
defaultColumnTypeName="Custom checkbox type"
data='[
["Criteria 1", "Criteria 2", "Criteria 3", "Criteria 4"],
["positive", "true", "positive", "false"],
["true", "false", "00", ""],
["", "0", "positive", "truthy"]]'
tableStyle='{"borderRadius":"2px"}'
></active-table>
DEFAULT_COLUMN_TYPES
- Type:
"Text"
|"Number"
|"Currency"
|"Date d-m-y"
|"Date m-d-y"
|"Checkbox"
|"Select"
|"Label"
Default column type names.