Repository navigation
api_fieldoptions
- action
- columnResizable
- create
- edit
- dateFormat
- dateLocale
- defaultValue
- dependsOn
- display
- explain
- input
- inputAttributes
- inputClass
- inputTitle
- key
- list
- listClass
- listClassEntry
- listClassHeader
- listEscapeHTML
- noCache
- options
- placeholder
- searchable
- searchAttributes
- searchDateFormat
- searchOptions
- searchPlaceholder
- searchType
- sorting
- title
- tooltip
- type
- visibility
- width
- SnapSelect (optional dependency)
A field definition defines the structure and behavior of a field of the record. It's generally formatted as:
FieldName: {
// Field options
}- Type: string
- Default: None
-
Valid options:
select,update,clone,delete - Description: by default - when specifying updateAction, cloneAction, deleteAction or the row-select checkboxes - FTable creates custom columns to accomodate room for these: checkboxes at the beginning of a row, update/clone/deleteAction become columns at the end. Specifying the action will cause the column to appear where you want it, allowing free positioning of the actions. See also Actions
- Type: Boolean
-
Default:
true -
Description: Indicates whether this column can be resized by the user. The table's
columnResizableoption must be set totrue(default) to use this option.
- Type: Boolean
-
Default:
true -
Description: Indicates whether this field is shown in the "create record" form. Defaults to
truefor normal fields andfalsefor action columns. For thekeyfield FTable forcescreatetotrueand the fieldtypeto'hidden', unless you explicitly setcreate: trueyourself (then the key is shown as a regular input).
- Type: String
- Default: none
-
Description: per-field override of the generic option
'defaultDateFormat'. Format of a date field if a datepicker is detected (fdatepicker currently). See the format of the accordingly detected datepicker. If no datepicker is detected, this value is ignored, but see'dateLocale'
- Type: String
- Default: None,
-
Description: per-field override of the generic option
'defaultDateLocale'. Defines the locale used to display values for a field of type 'date' in case no specific datepicker is used. Example:'nl-BE'or'en-US'.
- Type: String
- Default: None
- Description: Sets a default value for the field. It must be a valid value (e.g., for an option list, it must be one of the options).
- Type: String (comma-separated field names)
- Default: None
- Description: Used to create cascaded dropdowns. If a combobox field depends on another combobox, FTable can automatically create cascaded dropdowns. The dependsOn can also be a text field (or anything that supports getting the value).
Example:
CountryId: {
title: 'Country',
options: 'Demo/GetCountryOptions',
list: false
},
CityId: {
title: 'City',
dependsOn: 'CountryId', // Cities depend on countries.
options: function (data) {
if (data.source == 'table') {
return 'Demo/GetCityOptions?countryId=0'; // Return URL for all cities.
}
return 'Demo/GetCityOptions?countryId=' + data.dependedValues.CountryId;
}
}A field can depend on multiple fields. Use a comma-separated string:
dependsOn: 'ContinentalId,CountryId'
(An array is not supported: FTable splits the value on commas, so dependsOn: ['ContinentalId', 'CountryId'] is ignored.)
The dependsOn option works in tandem with dependedValues, as shown in the example above.
- Type: Function
- Default: None
- Description: Allows you to define a fully custom column for the table. The return value of this function is shown in the table.
Example:
TestColumn: {
title: 'Test',
display: function (data) {
return '<b>test</b>';
}
}-
data.record: Contains the record of the row. -
data.value: Contains the value of this column of the row, just a handy shortcut for data.record.colname -
data.displayValue: Contains the display value of this column of the row if no function was defined, very handy if you just want to change colors or so
Use this for calculated columns, child tables, etc.
- Type: Boolean
-
Default:
true -
Description: Indicates whether this field is shown in the "edit record" form. Defaults to
truefor normal fields andfalsefor action columns. For thekeyfield FTable forcesedittotrueand the fieldtypeto'hidden', unless you explicitly setedit: trueyourself (then the key is shown as a regular input).
- Type: String
- Default: None
- Description: Allows you to create an extra explanation for an input field (in the create/edit forms) just below the input field.
- Type: Function
- Default: None
- Description: Allows you to define a fully custom input element for create/edit forms.
Example:
Name: {
title: 'Name',
input: function (data) {
if (data.record) {
return '<input type="text" name="Name" value="' + data.record.Name + '" />';
} else {
return '<input type="text" name="Name" value="Enter your name" />';
}
}
}-
data.formType: Can be'create'or'edit'. -
data.inputField: The original input field (vanilla DOM element). -
data.record: The editing record (for'edit'forms). -
data.field: The field definition itself.
The data.inputField can come in handy if you just want to prepend something to the input field but don't want to code the field itself again. As an example, here is a field called "files" that in the list (display) shows a list of uploaded files and in the create/edit shows this list before the files-input field:
files: {
title: 'Files',
type: 'file',
inputAttributes: "multiple",
searchable: false,
sorting: false,
display: function (data) {
if (data.record && data.record['files']) {
return data.record['files'];
}
},
input: function (data) {
if (data.record && data.record['files']) {
let val = data.record['files'];
val += data.inputField.outerHTML;
return val;
} else {
return data.inputField;
}
}
}Another example that adds the input field original value above the input itself:
description: {
title: 'Description',
type: 'textarea',
list: false,
input: function (data) {
const container = document.createElement('div');
const span = document.createElement('span');
span.innerHTML = data.record['description'];
container.appendChild(span);
container.appendChild(data.inputField);
return container.outerHTML;
}
}- Type: String
- Default: None
- Description: Adds html attributes to the input element for this field in create/edit forms. FTable does form validation (as a regular form) before submit, so if you set this to e.g. "required", the required attribute will be set to the input field.
MyTextField: {
title: 'My phone is required',
inputAttributes: "size='60' required"
}- Type: String
- Default: None
- Description: Adds one or more CSS classes to the input element for this field in create/edit forms.
- Type: String
- Default: None
-
Description: Sets a different title for the field in create/edit forms. If not set, the
titleoption is used.
-
Type: Boolean
-
Default:
false -
Description: Indicates whether this field is the primary key of the record. Every record must have one key field.
-
In the edit/create modals, the key field is always included: by default FTable forces the field
typeto'hidden'(so a hidden input carrying the key is posted under the key field name). If you setedit(orcreate) explicitly totrue, the key is shown as a regular editable input instead.
- Type: Boolean
-
Default:
true - Description: Indicates whether this field is shown in the table.
- Type: String
- Default: None
-
Description: Adds a CSS class to the table cell (
<th>and<td>) for this field. Applied to columns in both header row and regular rows.
- Type: String
- Default: None
-
Description: Adds a CSS class to the table body cell (
<td>) for this field.
- Type: String
- Default: None
-
Description: Adds a CSS class to the table header cell (
<th>) for this field.
- Type: Boolean
- Default: False
- Description: if set to true, the value of the field will be escaped before showing it in the table. Might be useful for e.g. text and textarea fields.
- Type: Boolean, Function or Object
-
Default:
false -
Description: Skips the option-list cache for this field.
truealways fetches fresh options, a function is called with{ context, ...params }(returntrueto bypass the cache), an object can set it per context:{ table: true, create: false, edit: true, search: true }. See also the general optionlistCache.
-
Type: Object, Array, URL, or Function
-
Default: None
-
Description: Defines the source for an option list (e.g., radio buttons, dropdown).
-
If this is defined but not the field type, the field type is assumed to be "select".
PhoneType: {
title: 'Phone type',
options: { '1': 'Home phone', '2': 'Office phone', '3': 'Cell phone' }
}PhoneType: {
title: 'Phone type',
options: [
{ Value: '1', DisplayText: 'Home phone' },
{ Value: '2', DisplayText: 'Office phone' },
{ Value: '3', DisplayText: 'Cell phone' }
]
}or, if the values and displayed texts are identical:
PhoneType: {
title: 'Phone type',
options: ['1','2','3','4']
}You can disable options (like for regular select options). Note: a selected property is not supported - which option is selected always follows the value of the record (or the defaultValue in a create form):
PhoneType: {
title: 'Phone type',
options: [
{ Value: '1', DisplayText: 'Home phone' },
{ Value: '2', DisplayText: 'Office phone', disabled: true },
{ Value: '3', DisplayText: 'Cell phone' }
]
}Option groups are supported by adding the "Group" property
PhoneType: {
title: 'Phone type',
options: [
{ Value: '1', DisplayText: 'Cat A', Group: 'Animals' },
{ Value: '2', DisplayText: 'Cat B', Group: 'Animals' },
{ Value: '3', DisplayText: 'Item X', Group: 'Things' },
]
}PhoneType: {
title: 'Phone type',
options: [
{ Value: '1', DisplayText: 'Home phone', Data: {'extra_attr1': 'value1', 'extra_attr2': 'value2' } },
{ Value: '2', DisplayText: 'Office phone' },
{ Value: '3', DisplayText: 'Cell phone' }
]
}These data-values will be added as data-attributes to the <option> elements of the select (they are not applied to radio buttons).
PhoneType: {
title: 'Phone type',
options: '/Demo/GetPhoneTypes.php'
}In this case an ajax request is made to the mentioned url. The server response should obey the following layout (with optional extra data-values):
{
"Result": "OK",
"Options": [
{ "DisplayText": "Home phone", "Value": "1" },
{ "DisplayText": "Office phone", "Value": "2" },
{ "DisplayText": "Cell phone", "Value": "3", "Data": {"extra_attr1": "value1", "extra_attr2": "value2" } }
]
}A php example to create this:
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$enhancedRows = array_map(function($row) {
return [
'Value' => $row['Value'],
'DisplayText' => $row['DisplayText'],
'Data' => [
'extra_attr1' => $row['extra_attr1'],
'extra_attr2' => $row['extra_attr2']
]
];
}, $rows);
header('Content-Type: application/json');
echo json_encode([
'Result' => 'OK',
'Options' => $enhancedRows
]);The function either returns an option list (array) or an url where options can be fetched:
PhoneType: {
title: 'Phone type',
options: function (data) {
if (data.source == 'table') {
return '/Demo/GetPhoneTypes.php?UserType=0';
}
return '/Demo/GetPhoneTypes.php?UserType=' + data.record.UserType;
}
}For optimization, FTable caches all option lists based on the URL and serves options from local cache if you use the exactly same URL. You can clear the cache if you call data.clearCache() method in your function.
IMPORTANT: FTable also uses this function to show the related field in the table for each shown record. This is because your record contains Value of the field, not DisplayText and FTable needs to show display text (instead of value) in the table. So, when data.source=='table', returning different URLs causes more than one download to list records in the table. This may be a major performance problem. So, as shown the sample above, return URL of all options while rendering the table (data.source=='table') and return filtered options in edit/create forms (if you need).
You may want to return the data from server with an AJAX request. The function may be asynchronous: FTable awaits the returned promise (result = await field.options(data)), so you can simply return a fetch() promise or use async function (data) {...}. See demo and fetch async option.
All possible options:
-
data.source: Can be'table','create','edit'or'search'. -
data.record: The related record. -
data.dependedValues: Values of depended fields (ifdependsOnis used). -
data.clearCache(): This method is used to clear the cache for the currently returning URL. So, you can ensure that your options will be re-downloaded. -
data.form: Reference to the create/edit form (as DOM element). It is only present while handling adependsOnchange, not on the initial render of the form.
- Type: text
- Default: None
-
Description: Allows an extra placeholder in the input field: for text-like inputs it is used as the placeholder attribute, for a
selectan empty first option with this text is prepended (and it is used as the text of the SnapSelect placeholder for multi-selects). It is not used for checkbox/radio fields.
- Type: Boolean
-
Default:
True -
Description: Indicates whether this column shows a search form in the toolbar if
'toolbarsearch'is set.
- Type: text
- Default: none
-
Description: like inputAttributes , but only for the searchbar select-field. If not specified,
inputAttributeswill be used if present
- Type: text
- Default: none
-
Description: like dateFormat , but only for the searchbar date-field. If not specified,
dateFormatwill be used if present
- Type: same forms as options
- Default: none
-
Description: like options , but only for the searchbar select-field. If not specified,
optionswill be used if present. Note: it is only used when the search input is actually a select (see searchType); a field without atypeonly becomes a searchbar select when it hasoptions.
- Type: text
- Default: None
-
Description: Allows an extra placeholder in the searchbar input field. If not specified, the placeholder value will be taken, and if that's empty a default is used:
"Search..."for text inputs,"Type or select..."for datalists and the multiselect placeholder for multi-selects (date search fields fall back to an empty placeholder).
- Type: String
- Default: empty (value of "type" is taken)
-
Description: the search type of a column is taken from the field type by default, but this allows to change that (so you can search via text on a select-field for example). Possible values are the same as type (
'text','date','checkbox','select','datalist', ...).
- Type: Boolean
-
Default:
true - Description: Indicates whether this column can be used to sort the table.
- Type: String
- Default: None
- Description: The column header in the table and label in the forms for this field.
- Type: String
- Default: None
- Description: The column html title which is shown as a tooltip when hovering over it.
- Type: String
-
Default:
'text' -
Description: The data type for this field. Possible values:
-
'password': Shows a password input. -
'textarea': Shows a textarea. -
'date': Shows a date picker. If fdatepicker is not installed/loaded, a html5 datepicker is used. If a field is type date and fdatepicker is installed, you can use the field optiondateFormat: Format of date. See fdatepicker formats -
'radio': Shows a radio button list, see options. -
'select': Shows a dropdown, see options. Also see inputAttributes and/or searchAttributes to add extra html attributes to the created select field (like"multiple", anddata-attributes to configure the optional SnapSelect). -
'checkbox': Shows a checkbox. If a field is checkbox, you can define additional field options:-
'values': Values for checked/unchecked states. Example: { '0' : 'Passive', '1' : 'Active' }. First value is for unchecked state, second value is for checked state. -
'label': By default, a checkbox's text changes when user changes the state of the checkbox. If you want to fix the text, you can set the label option for this field (string).
-
-
'hidden': Renders the field as a hidden input in the create/edit forms (no label, no visible input). Usevisibilityorlistto control whether the column shows in the table. You may want to use the optiondefaultValuewith hidden types, so the given default value is automatically set as value for the hidden field when the form is created. -
'file': Shows a file input. -
'range','week','datetime-local',...: any valid html5 input-type -
'datalist': this also needs the'options'for its values
-
mydatalist: {
title: 'My Datalist input',
type: 'datalist',
options: ['Option 1', 'Option 2', 'Option 3']
}- Type: String
-
Default:
'visible' -
Description: Controls the visibility of the column. Possible values:
-
'fixed': Always visible (cannot be hidden by the user). -
'visible': Visible by default (can be hidden by the user). -
'hidden': Hidden by default (can be shown by the user). -
'separator': indicates this column is only used as a separator title in the column visibility menu (when right-clicking on the column headers)
-
- Type: Percentage
-
Default: none - all visible columns get an equal share (
100% / number of visible columns) -
Description: The width of the column in the table (e.g.,
'30%'). Ensure all column widths add up to 100%. If you resize a column with the mouse, the calculated widths are stored in your user preferences.
SnapSelect (@liedekef/snapselect) is an optional library that replaces a plain <select> with a modern dropdown (search, tags, select-all, clear button, ajax, ...). FTable has no hard dependency on it: FTable only enhances fields where the select is created with the multiple attribute, and only when SnapSelect is loaded. Everything else (single selects, the page-size select, ...) stays a native <select>.
FTable works without SnapSelect; nothing breaks if it is absent.
Load SnapSelect's CSS and JS before you create the FTable instance (its global SnapSelectClass is what FTable looks for):
<link rel="stylesheet" href="/path/to/snapselect/dist/css/snapselect.min.css">
<script src="/path/to/snapselect/dist/js/snapselect.min.js"></script>Or with npm: npm install @liedekef/snapselect and import @liedekef/snapselect/dist/css/snapselect.min.css + the js file from dist/js/snapselect.min.js.
Only selects FTable builds through its multi-select wrapper are enhanced (_buildMultiSelect()):
- a create/edit form field of type
'select'(or a field withoptions) whoseinputAttributescontainmultiple:
Tags: {
title: 'Tags',
options: '/Demo/GetTagOptions',
inputAttributes: "multiple data-live-search=true data-select-all-option=true"
}- the searchbar select of a column whose
searchAttributes(orinputAttributes) containmultiple:
Tags: {
title: 'Tags',
options: '/Demo/GetTagOptions',
searchAttributes: "multiple data-live-search=true"
}Without SnapSelect these are plain native <select multiple> elements (wrapped in a div.ftable-multiselect-wrap), so your page keeps working.
SnapSelect reads its configuration from data- attributes on the <select> element, and FTable copies everything from inputAttributes / searchAttributes onto that element. Supported attributes include:
| Attribute | Meaning |
|---|---|
multiple |
turns the field into a multi-select (this is what triggers SnapSelect) |
data-live-search |
show a search box inside the dropdown (true/false) |
data-placeholder |
placeholder text - FTable fills this from the field placeholder (or the multiSelectPlaceholder message) automatically |
data-select-all-option |
add a "Select All" entry (multi-select only) |
data-select-optgroups |
clicking an optgroup label selects/deselects the whole group |
data-max-selections |
maximum number of selected values |
data-show-clear-button |
show a clear ("x") button |
data-close-on-select |
close the dropdown after picking an option |
data-default-text |
text shown when nothing is selected |
Other option properties (Data on options, option groups, disabled) keep working, because SnapSelect is built on top of the real <select> - the change events FTable listens for are still fired on that element.
The instance is stored on the select element as select._snapselect, so you can call SnapSelect's own API (e.g. clear(), setPlaceholder(), refresh()) on it. FTable itself uses _snapselect.clear() when you press the search Reset button.