Options
All
  • Public
  • Public/Protected
  • All
Menu

A generic controller for tables. It provides information about the available columns and maintains state regarding their sort order and direction. In addition, it supports simple filtering based on cell content.

Hierarchy

  • TableController

Index

Constructors

  • new TableController(columns: string[][], options: { sortKey: string; sortOrder: string }): TableController
  • Creates a new controller for a table with the given numer of columns.

    Parameters

    • columns: string[][]

      the columns as a list of pairs of column key and column label. Labels may be functions which are invoked with the table controller as this and the key as argument if a label is required.

    • options: { sortKey: string; sortOrder: string }
      • sortKey: string

        the initial sort key

      • sortOrder: string

        the initial sort order

    Returns TableController

Properties

_filterKey: null | string = ''
_keys: string[] = []
_labelsByKey: Map<string, string | ((key: string) => string)> = ...
_sortKey: string = ''
_sortOrders: Map<string, number> = ...

Accessors

  • get keys(): string[]

Methods

  • breakBeforeDots(text: string): string
  • A convenience function that inserts word breaks (&#x200b) before every dot in the given text and returns the result.

    Parameters

    • text: string

      the text

    Returns string

  • clearFilter(event: Event): void
  • A convenience method for clearing an input element that is used to specify a filter. Searches for an input element in the event.target's enclosing form element and sets its value to the empty string.

    Parameters

    • event: Event

      the event

    Returns void

  • filter(data: any[]): any[]
  • Sort and filter the given data according to the current state of the controller. Returns the sorted data.

    Parameters

    • data: any[]

    Returns any[]

  • filterBy(filter: string): void
  • Sets a filter for the data.

    Parameters

    • filter: string

      the string to match

    Returns void

  • label(key: string): undefined | string
  • Returns the column label for the given column key.

    Parameters

    • key: string

      the column key

    Returns undefined | string

  • sortBy(key: string, order?: string): void
  • This method sets the primary sort key. If the order is undefined, and the current sort key is the same as the specified key, the current sort order is inverted.

    Parameters

    • key: string

      the column key

    • Optional order: string

      the sort order ('up' for ascending and 'down' for descending) or undefined

    Returns void

  • sortOrder(key: string): undefined | number
  • Returns the sort order of the column with the given key (1 for "up" and -1 for "down").

    Parameters

    • key: string

      the column key

    Returns undefined | number

  • sortedByAsc(key: string): boolean
  • Returns true if given key is the current sort key and the current sort order for is ascending.

    Parameters

    • key: string

      the column key

    Returns boolean

  • sortedByDesc(key: string): boolean
  • Returns true if given key is the current sort key and the current sort order for is descending.

    Parameters

    • key: string

      the column key

    Returns boolean

  • updateFilter(event: Event): void
  • A convenience method to update the filter from the value of the passed in event.

    Parameters

    • event: Event

      the event which must have a currentTarget with a value attribute.

    Returns void

Generated using TypeDoc