Skip to content
Nathanael CHERRIER edited this page Nov 19, 2016 · 8 revisions

Instantiation

new Nativetable(id: number, options?: {
    sources?: Object[] = [],
    columns?: string[] = [],
    filters?: {
       $and?: Object = {},
       $or?: Object = {}
    } = {},
    pagination?: {
        maxLength?: number = -1
    } = {}
} = {})

To init a Nativetable object only id argument is required.

In options argument,

  • sources is a list of objects the user wants to display in a table.
  • columns is a list of key the user wants to display. When this argument is used, only key in columns are displaying.
  • filters is an object which exposes filtering conditions.
  • pagination.maxLength is the maximum number of items shown in one page.

Filtering with options.filters

options.filters can contain two keys: $and and $or where conditions are grouped.

In the $and key, the logical operator used between each condition is AND. Similarly, in the $or key, the logical operator used between each condition is OR.

Between $and and $or, the logical operator user is AND.

Between each value of one condition, the logical operator user is OR.

The keys of $and and $or object must be the same keys that you want to filter in options.sources. The value for each key must be an array of wanted value or a closure that returns a boolean and take in parameters the value of the key you want to test in each object of options.sources.

Atribute

sources

nt.sources: Object[]

The sources of the created table

filtered

nt.filtered: Object[]

It is a read only atribute.

The filtered sources. If options.filters is not used the default value of nt.filtered is nt.sources.

paginated

nt.paginated: Object[][]

It is a read only atribute.

The paginated sources. If options.pagination.maxLength is not used the default value of nt.paginated is nt.sources.

columns

nt.columns: string[]

The list of keys to use as columns Only these keys are displaying event if others are available in nt.sources.

It is mandatory to display at least on column. When nt.columns = [] is used, Nativetable show all keys available in nt.sources as default.

Methods

draw

nt.draw(): void

This method draw the table in the DOM.

reload

nt.reload(rows?: Object[]): void

Force the reloading of pagination and redraw the table. If data (rows) is passed in argument, rows is passed to nt.sources before the reloading.

Clone this wiki locally