Field
model/field.Field
Number datasheet column operations and information.
To manipulate the number datasheet columns, you can use useField (single column information), useFields (multiple column information).
Accessors
id
• get
id(): string
The ID for this model.
Returns
string
Example
console.log(myField.id);
// => 'fld1234567'
name
• get
name(): string
The name of the field. Can be watched.
Returns
string
Example
console.log(myField.name);
// => 'Name'
type
• get
type(): FieldType
The type of the field. Can be watched. FieldType
Returns
Example
console.log(myField.type);
// => 'SingleLineText'
description
• get
description(): null
| string
The description of the field, if it has one. Can be watched.
Returns
null
| string
Example
console.log(myField.description);
// => 'This is my field'
property
• get
property(): FieldType
The configuration property of the field. The structure of the field's property depend on the field's type. null if the field has no property. Can be watched. Refer to FieldType.
Returns
any
Example
import { FieldType } from '@apitable/widget-sdk';
if (myField.type === FieldType.Currency) {
console.log(myField.options.symbol);
// => '¥'
}
isComputed
• get
isComputed(): boolean
true if this field is computed, false otherwise. A field is "computed" if it's value is not set by user input (e.g. autoNumber, magic lookup, magic formula, etc.). Can be watched
Returns
boolean
Example
console.log(mySingleLineTextField.isComputed);
// => false
console.log(myAutoNumberField.isComputed);
// => true
isPrimary
• get
isPrimary(): boolean
true if this field is its parent table's primary field, false otherwise. Should never change because the primary field of a datasheet cannot change.
Returns
boolean
required
• get
required(): null
| boolean
Is the magic form required.
Returns
null
| boolean
Methods
getPropertyInView
▸ getPropertyInView(viewId
): null
| IPropertyInView
Get the current view feature properties, such as whether the field is hidden in a view
Parameters
Name | Type | Description |
---|---|---|
viewId | string | the view ID |
Returns
null
| IPropertyInView
Example
const propertyInView = field.getPropertyInView('viwxxxxx');
console.log(propertyInView?.hidden)
updateDescription
▸ updateDescription(description
): Promise
<void
>
Updates the description for this field.
Throws an error if the user does not have permission to update the field, or if an invalid description is provided.
Parameters
Name | Type | Description |
---|---|---|
description | null | string | new description for the field |
Returns
Promise
<void
>
Example
field.updateDescription('this is a new description')
updateProperty
▸ updateProperty(property
, options?
): Promise
<void
>
Beta API, future changes are possible.
Updates the property for this field, tips: that the update property configuration must be overwritten in full.
Throws an error if the user does not have permission to update the field, if invalid property are provided, if this field has no writable property, or if updates to this field type is not supported.
Refer to FieldType for supported field types, the write format for property, and other specifics for certain field types.
Parameters
Name | Type | Description |
---|---|---|
property | any | new property for the field. |
options? | IEffectOption | optional options to affect the behavior of the update. |
Returns
Promise
<void
>
Example
function addOptionToSelectField(selectField, nameForNewOption) {
const updatedOptions = {
options: [
...selectField.options,
{name: nameForNewOption},
]
};
if (selectField.hasPermissionToUpdateOptions(updatedOptions)) {
selectField.updateProperty(updatedOptions);
}
}
hasPermissionForUpdateDescription
▸ hasPermissionForUpdateDescription(description?
): boolean
Checks whether the current user has permission to perform the given description update.
Parameters
Name | Type | Description |
---|---|---|
description? | string | new description for the field, Length limit 200. |
Returns
boolean
Example
const canUpdateFieldDescription = field.hasPermissionForUpdateDescription();
if (!canUpdateFieldDescription) {
alert('not allowed!');
}
hasPermissionForUpdateProperty
▸ hasPermissionForUpdateProperty(property?
): boolean
Check whether the current user has permission to perform the given option update.
Property about the update write format, refer to FieldType.
Parameters
Name | Type | Description |
---|---|---|
property? | any | new property for the field. |
Returns
boolean
Example
const canUpdateFieldProperty = field.hasPermissionForUpdateProperty();
if (!canUpdateFieldProperty) {
alert('not allowed!');
}
checkPermissionForUpdateProperty
▸ checkPermissionForUpdateProperty(property?
): IPermissionResult
Check whether the current user has permission to perform the given option update.
Parameters
Name | Type | Description |
---|---|---|
property? | any | new property for the field. |
Returns
Description
Accepts partial input, in the same format as updateProperty.
property about the update write format, refer to FieldType.
Returns {acceptable: true}
if the current user can update the specified property.
Returns {acceptable: false, message: string}
if no permission to operate, message may be used to display an error message to the user.
Example
// Check whether the current user has permission to perform the given property update,
// when the update is accompanied by a write, it can also be verified at the same time.
const updatePropertyCheckResult = field.checkPermissionForUpdateProperty({
defaultValue: '1',
});
if (!updatePropertyCheckResult.acceptable) {
alert(updatePropertyCheckResult.message);
}
// Check if user could potentially update a property.
// Use when you don't know the specific a property you want to update yet (for example,
// to show or hide UI controls that let you start update a property.)
const updatePropertyCheckResult =
field.checkPermissionForUpdateProperty();