Skip to content

@serenity-is/corelib / PropertyGrid

Class: PropertyGrid<P>

Defined in: src/ui/widgets/propertygrid.tsx:479

A widget that renders a set of PropertyItems as a form, organizing them into categories and/or tabs, and manages loading/saving values to and from the underlying editors.

Extends

Type Parameters

P

P extends PropertyGridOptions = PropertyGridOptions

Widget props type, constrained to PropertyGridOptions.

Constructors

Constructor

new PropertyGrid<P>(props): PropertyGrid<P>

Defined in: src/ui/widgets/widget.ts:157

Creates a widget bound to the given props, resolving the DOM node, associating the widget with it and rendering its contents.

Parameters

props

WidgetProps<P>

The widget props, including the target element.

Returns

PropertyGrid<P>

Inherited from

Widget.constructor

Properties

domNode

readonly domNode: HTMLElement

Defined in: src/ui/widgets/widget.ts:98

The DOM node this widget is bound to.

Inherited from

Widget.domNode


idPrefix

readonly idPrefix: string

Defined in: src/ui/widgets/widget.ts:96

The id prefix used for this widget's child element ids.

Inherited from

Widget.idPrefix


options

protected readonly options: WidgetProps<P>

Defined in: src/ui/widgets/widget.ts:92

The widget's options/props.

Inherited from

Widget.options


uniqueName

readonly uniqueName: string

Defined in: src/ui/widgets/widget.ts:94

A unique name for this widget instance, used for event namespacing.

Inherited from

Widget.uniqueName


[typeInfo]

static [typeInfo]: ClassTypeInfo<"Serenity.">

Defined in: src/ui/widgets/propertygrid.tsx:483

Overrides

Widget.[typeInfo]


defaultDeferInit

static defaultDeferInit: boolean = false

Defined in: src/ui/widgets/widget.ts:106

Whether the classes that neither have a DeferInitAttribute (see Attributes.deferInit) nor override deferredInit, nor have a base class that says true or false, defer their initialization; false by default. An application whose widgets are written for deferred initialization turns it on in its script init, before any widget is created.

Inherited from

Widget.defaultDeferInit


isComponent

readonly static isComponent: true = true

Defined in: src/ui/widgets/widget.ts:530

Inherited from

Widget.isComponent

Accessors

element

Get Signature

get element(): Fluent

Defined in: src/ui/widgets/widget.ts:216

Returns a Fluent(this.domNode) object

Returns

Fluent

Inherited from

Widget.element


initialized

Get Signature

get protected initialized(): boolean

Defined in: src/ui/widgets/widget.ts:137

Whether the widget is initialized: always for one that initializes in its constructor, and for one that defers its initialization (see isDeferredInit), once its deferredInit is done.

Returns

boolean

Inherited from

Widget.initialized


props

Get Signature

get props(): WidgetProps<P>

Defined in: src/ui/widgets/widget.ts:503

Returns the widget's props/options.

Returns

WidgetProps<P>

Inherited from

Widget.props


usesDeferredInit

Get Signature

get protected usesDeferredInit(): boolean

Defined in: src/ui/widgets/widget.ts:129

Whether this widget defers its initialization, see isDeferredInit.

Returns

boolean

Inherited from

Widget.usesDeferredInit


value

Get Signature

get value(): any

Defined in: src/ui/widgets/propertygrid.tsx:934

Gets the current values of all editors as an object.

Returns

any

Set Signature

set value(val): void

Defined in: src/ui/widgets/propertygrid.tsx:942

Loads values from an object into all editors.

Parameters
val

any

The object containing values to load.

Returns

void

Methods

addCssClass()

protected addCssClass(): void

Defined in: src/ui/widgets/widget.ts:223

Adds the widget's CSS class to its DOM node.

Returns

void

Inherited from

Widget.addCssClass


addValidationRule()

Call Signature

addValidationRule(rule, uniqueName?): void

Defined in: src/ui/widgets/widget.ts:267

Adds a validation rule to the widget's DOM node.

Parameters
rule

(input) => string

The validation rule function, or a unique name when the two-argument overload is used.

uniqueName?

string

A unique name for the rule, or the rule function when the two-argument overload is used.

Returns

void

Inherited from

Widget.addValidationRule

Call Signature

addValidationRule(uniqueName, rule): void

Defined in: src/ui/widgets/widget.ts:268

Adds a validation rule to the widget's DOM node.

Parameters
uniqueName

string

A unique name for the rule, or the rule function when the two-argument overload is used.

rule

(input) => string

The validation rule function, or a unique name when the two-argument overload is used.

Returns

void

Inherited from

Widget.addValidationRule


afterRender()

protected afterRender(callback): void

Defined in: src/ui/widgets/widget.ts:359

Queues a callback to run after the widget's contents are rendered.

Parameters

callback

() => void

The callback to run after rendering.

Returns

void

Inherited from

Widget.afterRender


attachValidationRules()

protected attachValidationRules(fieldElement): void

Defined in: src/ui/widgets/propertygrid.tsx:545

Adds the validation rules of a field, see PropertyItem.validationRules, to the element of its editor as a custom rule of the validator, once its editor is loaded. The editor has to be one the validator validates, i.e. an input, a select or a text area, like for the required fields.

Parameters

fieldElement

PropertyFieldElement

The field.

Returns

void


byId()

protected byId<TElement>(id): Fluent<TElement>

Defined in: src/ui/widgets/widget.ts:279

Finds a child element by its prefix-relative id.

Type Parameters

TElement

TElement extends HTMLElement = HTMLElement

Parameters

id

string

The id relative to the widget's id prefix.

Returns

Fluent<TElement>

A Fluent wrapper for the matching element.

Inherited from

Widget.byId


canModifyItem()

protected canModifyItem(item): boolean

Defined in: src/ui/widgets/propertygrid.tsx:986

Determines whether a property item may be modified in the current mode.

Parameters

item

PropertyItem

The property item to check.

Returns

boolean

True if the item can be modified.


change()

change(handler): void

Defined in: src/ui/widgets/widget.ts:310

Registers a change handler on the widget's DOM node.

Parameters

handler

(e) => void

The change event handler.

Returns

void

Inherited from

Widget.change


changeSelect2()

changeSelect2(handler): void

Defined in: src/ui/widgets/widget.ts:319

Registers a change handler that ignores changes originating from combobox setting values.

Parameters

handler

(e) => void

The change event handler.

Returns

void

Inherited from

Widget.changeSelect2


checkValidationRules()

protected checkValidationRules(fieldElement): string

Defined in: src/ui/widgets/propertygrid.tsx:567

Checks the value of a field by its validation rules, unless it is read only, as its value can't be changed then. Hidden fields are not validated by the validator.

Parameters

fieldElement

PropertyFieldElement

The field.

Returns

string

The message of the first rule its value is not valid by, or null.


commitEdits()

commitEdits(): Promise<boolean>

Defined in: src/ui/widgets/propertygrid.tsx:919

Commits pending edits on all editors that support it.

Returns

Promise<boolean>

True if all commits succeeded, false if any editor rejected.


deferredInit()

protected deferredInit(): void | PromiseLike<void>

Defined in: src/ui/widgets/widget.ts:440

Does the initialization of a widget that defers it (see isDeferredInit), once, when init or initAsync is called after all its constructors are done. The base classes initialize what their constructors would, e.g. the contents, the form or the columns, and a subclass does the work its constructor would do after await super.deferredInit(), which may wait too. The part before its first await runs at once, so a widget that is made and inited has its contents.

Returns

void | PromiseLike<void>

Inherited from

Widget.deferredInit


destroy()

destroy(): void

Defined in: src/ui/widgets/propertygrid.tsx:733

Destroys all field editors and clears the grid contents.

Returns

void

Overrides

Widget.destroy


enumerateItems()

enumerateItems(callback): void

Defined in: src/ui/widgets/propertygrid.tsx:799

Invokes a callback for each rendered field with its property item and editor widget.

Parameters

callback

(p1, p2) => void

Callback receiving the property item and editor widget.

Returns

void


findById()

protected findById<TElement>(id): TElement

Defined in: src/ui/widgets/widget.ts:291

Finds a child element by its prefix-relative id.

Type Parameters

TElement

TElement extends HTMLElement = HTMLElement

Parameters

id

string

The id relative to the widget's id prefix.

Returns

TElement

The matching element, or null if not found.

Inherited from

Widget.findById


get_editors()

get_editors(): Widget<any>[]

Defined in: src/ui/widgets/propertygrid.tsx:759

Returns the editor widgets for all rendered fields.

Returns

Widget<any>[]

Array of editor widgets.


get_idPrefix()

get_idPrefix(): string

Defined in: src/ui/widgets/propertygrid.tsx:775

Returns the id prefix used by this grid.

Returns

string

The id prefix.


get_items()

get_items(): PropertyItem[]

Defined in: src/ui/widgets/propertygrid.tsx:767

Returns the property items for all rendered fields.

Returns

PropertyItem[]

Array of property items.


get_mode()

get_mode(): PropertyGridMode

Defined in: src/ui/widgets/propertygrid.tsx:813

Returns the current grid mode (insert or update).

Returns

PropertyGridMode

The current PropertyGridMode.


getConditionStates()

protected getConditionStates(): Map<PropertyFieldElement, PropertyFieldConditionState>

Defined in: src/ui/widgets/propertygrid.tsx:618

Gets what the conditions make of the fields that have some, for the current values of the fields. A field hidden by its own condition also hides the fields whose visibility conditions are on it, as they depend on a field that can't be seen.

Returns

Map<PropertyFieldElement, PropertyFieldConditionState>

The states by the field elements.


getConditionValue()

protected getConditionValue(name): any

Defined in: src/ui/widgets/propertygrid.tsx:599

Gets the current value of a field, for the conditions of the others, which is undefined when there is no such field, or its editor is not loaded yet.

Parameters

name

string

The name of the field.

Returns

any


getCssClass()

protected getCssClass(): string

Defined in: src/ui/widgets/widget.ts:231

Returns the CSS class(es) applied to the widget's DOM node.

Returns

string

The space-separated CSS class string.

Inherited from

Widget.getCssClass


getCustomAttribute()

protected getCustomAttribute<TAttr>(attrType, inherit): TAttr

Defined in: src/ui/widgets/widget.ts:351

Returns a custom attribute applied to the widget's type.

Type Parameters

TAttr

TAttr extends CustomAttribute

Parameters

attrType

(...args) => TAttr

The attribute type to look up.

inherit

boolean = true

Whether to search inherited types; defaults to true.

Returns

TAttr

The matching attribute, or null.

Inherited from

Widget.getCustomAttribute


getEditorsLoading()

getEditorsLoading(): Promise<void>

Defined in: src/ui/widgets/propertygrid.tsx:785

Gets a promise for the editors that are still loading, as their types are loaded on demand, e.g. a lazily loaded editor, or as they defer their initialization, e.g. loading their lookups, see PropertyGridOptions.deferInit. The values can't be saved, see save, until they are loaded.

Returns

Promise<void>

The promise, or null when all the editors are loaded.


getGridField()

getGridField(): Fluent

Defined in: src/ui/widgets/widget.ts:302

Returns the closest .field element containing the widget's DOM node.

Returns

Fluent

A Fluent wrapper for the grid field.

Inherited from

Widget.getGridField


hasConditions()

protected hasConditions(): boolean

Defined in: src/ui/widgets/propertygrid.tsx:590

Gets whether any field has conditions on the values of the others.

Returns

boolean


init()

init(): this

Defined in: src/ui/widgets/widget.ts:375

Initializes the widget: one that defers its initialization (see isDeferredInit) starts it, and it may end later, see initAsync; others are initialized by their constructors already.

Returns

this

This widget instance.

Inherited from

Widget.init


initAsync()

initAsync(): Promise<PropertyGrid<P>>

Defined in: src/ui/widgets/widget.ts:388

Initializes the widget once and waits until it is initialized: one that defers its initialization (see isDeferredInit) runs its deferredInit, the first time it is called; others are initialized by their constructors.

Returns

Promise<PropertyGrid<P>>

A promise of this widget, which is rejected when its initialization fails.

Inherited from

Widget.initAsync


initNow()

protected initNow(): boolean

Defined in: src/ui/widgets/widget.ts:146

Starts the initialization of a widget that defers it, if it hasn't started, and tells whether it is initialized now, e.g. as it had nothing to wait for. A method that needs the widget initialized waits for initAsync when it is not, e.g. if (!this.initNow()) return void this.initAsync().then(...).

Returns

boolean

Inherited from

Widget.initNow


internalRenderContents()

internalRenderContents(): void

Defined in: src/ui/widgets/widget.ts:462

Renders the widget's contents and runs any queued after-render callbacks.

Returns

void

Inherited from

Widget.internalRenderContents


legacyTemplateRender()

protected legacyTemplateRender(): boolean

Defined in: src/ui/widgets/widget.ts:487

Renders the widget from a legacy getTemplate string, if defined.

Returns

boolean

True if a legacy template was rendered.

Inherited from

Widget.legacyTemplateRender


load()

load(source): void

Defined in: src/ui/widgets/propertygrid.tsx:860

Loads values from a source object into all field editors.

Parameters

source

any

The source object to read values from.

Returns

void


render()

render(): any

Defined in: src/ui/widgets/widget.ts:449

Returns the main element for this widget or the document fragment. As widgets may get their elements from props unlike regular JSX widgets, this method should not be overridden. Override renderContents() instead.

Returns

any

Inherited from

Widget.render


renderContents()

protected renderContents(): any

Defined in: src/ui/widgets/propertygrid.tsx:495

Renders the property grid contents, building categories/tabs and loading the initial value.

Returns

any

The rendered contents.

Overrides

Widget.renderContents


save()

save(target?): any

Defined in: src/ui/widgets/propertygrid.tsx:895

Saves all field editor values into a target object.

Parameters

target?

any

Optional target object; a new object is created if omitted.

Returns

any

The object containing the saved values.


set_mode()

set_mode(value): void

Defined in: src/ui/widgets/propertygrid.tsx:821

Sets the grid mode and refreshes the interface.

Parameters

value

PropertyGridMode

The new PropertyGridMode.

Returns

void


syncOrAsyncThen()

protected syncOrAsyncThen<T>(syncMethod, asyncMethod, then): void

Defined in: src/ui/widgets/widget.ts:514

Runs a method synchronously or asynchronously depending on the widget's useAsync flag, then invokes a continuation.

Type Parameters

T

T

Parameters

syncMethod

() => T

The synchronous method to run.

asyncMethod

() => PromiseLike<T>

The asynchronous method to run.

then

(v) => void

The continuation invoked with the result.

Returns

void

Inherited from

Widget.syncOrAsyncThen


updateConditionContainers()

protected updateConditionContainers(): void

Defined in: src/ui/widgets/propertygrid.tsx:700

Hides the categories and the tabs whose fields are all hidden, when they have a field with a visibility condition, so the others are left as they were.

Returns

void


updateConditions()

updateConditions(): void

Defined in: src/ui/widgets/propertygrid.tsx:672

Updates the fields whose conditions changed by the current values of the fields, and the categories and tabs they are in. A field whose conditions didn't change is left as it is, e.g. one a dialog made read only itself. It is called as the values change, and can be called after setting the value of an editor in code, which doesn't tell it.

Returns

void


updateFieldElement()

protected updateFieldElement(fieldElement): void

Defined in: src/ui/widgets/propertygrid.tsx:1038

Updates a single field element in the current mode.

Parameters

fieldElement

PropertyFieldElement

The field element to update.

Returns

void


updateInterface()

updateInterface(): void

Defined in: src/ui/widgets/propertygrid.tsx:1046

Refreshes the read-only/required state and visibility of all fields, including what their conditions make of them.

Returns

void


useIdPrefix()

protected useIdPrefix(): IdPrefixType

Defined in: src/ui/widgets/widget.ts:525

Returns an id prefix helper for resolving child element ids.

Returns

IdPrefixType

An IdPrefixType proxy for this widget's id prefix.

Inherited from

Widget.useIdPrefix


canModifyItem()

static canModifyItem(item, mode?): boolean

Defined in: src/ui/widgets/propertygrid.tsx:955

Determines whether a property item may be modified in the given mode, taking insert/update permissions into account.

Parameters

item

PropertyItem

The property item to check.

mode?

PropertyGridMode

The grid mode; defaults to update semantics when omitted.

Returns

boolean

True if the item can be modified.


create()

static create<TWidget, P>(params): TWidget

Defined in: src/ui/widgets/widget.ts:333

Creates a widget instance from the given params, appending its element to the container and invoking the init/init callbacks.

Type Parameters

TWidget

TWidget extends Widget<P>

P

P

Parameters

params

CreateWidgetParams<TWidget, P>

The widget creation params.

Returns

TWidget

The created widget instance.

Inherited from

Widget.create


createDefaultElement()

static createDefaultElement(): HTMLElement

Defined in: src/ui/widgets/widget.ts:209

Creates the default DOM element for a widget.

Returns

HTMLElement

A new div element.

Inherited from

Widget.createDefaultElement


getWidgetName()

static getWidgetName(type): string

Defined in: src/ui/widgets/widget.ts:256

Returns the widget name for a type, used for association and unique names.

Parameters

type

Function

The widget type.

Returns

string

The widget name.

Inherited from

Widget.getWidgetName


isDeferredInit()

static isDeferredInit(type, requested?): boolean

Defined in: src/ui/widgets/widget.ts:118

Gets whether a widget of a type defers its initialization to deferredInit, which init or initAsync runs once all the constructors are done, and which may wait. It is as the DeferInitAttribute (see Attributes.deferInit) of the type or a base class says, true for a class that overrides deferredInit, else as defaultDeferInit says. It throws when the type and its base classes say conflicting things, e.g. a class has false but overrides deferredInit.

Parameters

type

Function

The widget type.

requested?

boolean

Whether the creator of the widget asks for it, see WidgetProps.deferInit, which counts only for a class whose own attribute says "optional".

Returns

boolean

Inherited from

Widget.isDeferredInit


loadFieldValue()

static loadFieldValue(source, fieldElement, mode?): void

Defined in: src/ui/widgets/propertygrid.tsx:835

Loads a field's value from a source object into its editor, applying defaults in insert mode.

Parameters

source

any

The source object to read values from.

fieldElement

PropertyFieldElement

The field element whose editor receives the value.

mode?

PropertyGridMode

The grid mode, used to apply insert defaults.

Returns

void


registerClass()

protected static registerClass<TypeName>(typeName, intfAndAttr?): ClassTypeInfo<TypeName>

Defined in: src/ui/widgets/widget.ts:538

Registers this type as a class with the given type name.

Type Parameters

TypeName

TypeName

Parameters

typeName

StringLiteral<TypeName>

The type name to register.

intfAndAttr?

(InterfaceType | AttributeSpecifier)[]

Optional interfaces and attributes.

Returns

ClassTypeInfo<TypeName>

The class type info.

Inherited from

Widget.registerClass


registerEditor()

protected static registerEditor<TypeName>(typeName, intfAndAttr?): EditorTypeInfo<TypeName>

Defined in: src/ui/widgets/widget.ts:553

Registers this type as an editor with the given type name.

Type Parameters

TypeName

TypeName

Parameters

typeName

StringLiteral<TypeName>

The type name to register.

intfAndAttr?

(InterfaceType | AttributeSpecifier)[]

Optional interfaces and attributes.

Returns

EditorTypeInfo<TypeName>

The editor type info.

Inherited from

Widget.registerEditor


saveFieldValue()

static saveFieldValue(target, fieldElement, canModify?): void

Defined in: src/ui/widgets/propertygrid.tsx:879

Saves a field's editor value into a target object when the item is modifiable.

Parameters

target

any

The target object to write values into.

fieldElement

PropertyFieldElement

The field element whose editor value is saved.

canModify?

boolean

Whether the item may be modified; defaults to the result of PropertyGrid.canModifyItem.

Returns

void


updateFieldElement()

static updateFieldElement(fieldElement, mode?, canModify?, conditions?): void

Defined in: src/ui/widgets/propertygrid.tsx:999

Updates a field element's editor read-only/required state and visibility based on the item and mode.

Parameters

fieldElement

PropertyFieldElement

The field element to update.

mode?

PropertyGridMode

The grid mode.

canModify?

boolean

Whether the item may be modified.

conditions?

PropertyFieldConditionState

What the conditions of the field make of it, which only add to the rest, e.g. a field hidden by a permission stays hidden.

Returns

void