@itrocks/list-properties
v0.2.0
Published
Marks class properties to show as columns in a list/table view
Maintainers
Readme
list-properties
Marks class properties to show as columns in a list/table view.
Usage
This module extends the @itrocks/reflect system to determine which class properties should be displayed in a list or table view.
To enable these extensions, call initListProperties() once at application startup.
Use the @List() decorator on a class to explicitly declare which properties are shown in list views.
You can also rely on default behaviour that omits
CollectionType properties
or selects only @Representative ones when more than 5 properties exist.
API
initListProperties
initListProperties(): voidCall this once at runtime during app initialisation.
This must be called before any module using listOf() or ReflectClass.listProperties() is loaded.
This extends the ReflectClass prototype with two new methods:
listProperties(): ReflectProperty[]- returns ReflectProperty instanceslistPropertyNames(): string[]- returns only the names
@List
@List(...properties: KeyOf<T>[])Marks the given properties to be listed in a table-like UI.
When no explicit property list is provided, a default list is inferred using:
- all non-collection properties (when ≤ 5),
- otherwise (more than 5) only the @Representative properties.
Parameters:
properties: the property names you want to include in list views.
Example:
@List('name', 'email', 'role')
class User {
email: string
name: string
password: string
role: Role
}listOf
listOf(target: ObjectOrType<T>): string[]Returns an ordered list of property names to be used in list views,
based on the @List() decorator value or default rules.
Template integration
This module is used in list rendering templates to dynamically generate column headers and data cells.
The following example uses the new ReflectClass.listProperties() method into an
@itrocks/template-insight template:
<!--%listProperties-->
<th data-property="{name}">{@display}</th>
<!--end-->These directives will iterate over the selected list properties, producing one column per entry. This allows the UI to adapt automatically to changes in your model classes.
