SortTable

SortTable

new SortTable()

Source:
Properties:
Name Type Description
source HTMLTableElement

source table

data Array

data array to be sorted

multidimensional Boolean

if data is single-dimensional (contains rows with data to be sorted as immediate array items: data [rowItem...]), then it is false. If it has blocks of data as items (each block containing an array of rows to be sorted: data [block [rowItem...]...]), then set it to true. Currently it supports only a two-level aggregation max (data->block->rowItem).

sortOrder SortOrder

instance of SortOrder

columns TableColumns

instance of TableColumns with a modified prototype (added sortable:true and .sortable to sortable columns)

Methods

(static) defineSortableColumns(columns, includedopt, excludedopt)

Source:

Checks the table columns array against the included/excluded columns arrays and adds a sortable:true property and a .sortable class to the sortable ones

Parameters:
Name Type Attributes Description
columns TableColumns

an instance of TableColumns

included Array <optional>

array of included columns indices

excluded Array <optional>

array of excluded columns indices

(static) listenForSort(delegatedTarget, columns, sortOrder)

Source:

sets up listeners for column headers available for click

Parameters:
Name Type Description
delegatedTarget HTMLElement

element that will receive clicks and see if they are valid, thead is recommended to boil down to header clicks only

columns TableColumns

array of table columns from SortTable#defineSortableColumns

sortOrder SortOrder

instance of SortOrder

Listens to Events:
  • event:click

(static) sortDimension(data, columns, sortOrder)

Source:

Splits sorting into one-column or two-column. The precedence of columns in sortOrder is the factor defining sort priority

Parameters:
Name Type Description
data Array

array containing row items to be sorted

columns TableColumns

array of table columns from SortTable#defineSortableColumns

sortOrder SortOrder

instance of SortOrder

(static) sorter()

Source:

Function that performs case insensitive sorting in the array. It can distinguish between numbers, numbers as strings, HTML and plain strings

sort(sortOrder)

Source:

Performs channeling of sorting based on whether this.data is multidimensional

Parameters:
Name Type Description
sortOrder SortOrder

instance of SortOrder passed by the SortOrder#sort on initial sort

Fires:

Events

reportal-table-sort

Source:

Event reporting that a table has been sorted

SortTable

new SortTable(options)

Source:

Makes a table sortable, gives API for sorting. It sorts data array, but doesn't move rows in the source table, because of differences in implementation

Parameters:
Name Type Description
options Object

options passed to configure the Sorting

Properties
Name Type Attributes Default Description
enabled Boolean false

enables sorting on a header of a table

source HTMLTableElement

source table sorting will be applied to

refSource HTMLTableElement <optional>

the floating header if any, will reflect and trigger sorting on header when scrolled.

defaultHeaderRow Number <optional>
-1

index of the row in thead (incremented from 0) that will have sorting enabled for columns. If -1 then last row.

included Array <optional>

Array of column indices (incremented from 0) that will have sorting enabled. If not specified, all columns will be sortable. Optionally excluded can be specified instead as a shorthand to pass only indices of columns to be excluded from sorting, assumning that others will be made sortable. It's important to count the column index in the defaultHeaderRow

excluded Array <optional>

Array of column indices (incremented from 0) that will be excluded from sorting. Can be used as a shorthand instead of included.

defaultSorting Object <optional>

an array of objects that specify default sorting

Properties
Name Type Description
column Number

column index

direction String

sort direction (asc|desc)

data Array

data with information for rows to be sorted

multidimensional Boolean <optional>
false

if data is single-dimensional (contains rows with data to be sorted as immediate array items: data [rowItem...]), then it is false. If it has blocks of data as items (each block containing an array of rows to be sorted: data [block [rowItem...]...]), then set it to true. Currently it supports only a two-level aggregation max (data->block->rowItem).

Methods

(static) defineSortableColumns(columns, includedopt, excludedopt)

Source:

Checks the table columns array against the included/excluded columns arrays and adds a sortable:true property and a .sortable class to the sortable ones

Parameters:
Name Type Attributes Description
columns TableColumns

an instance of TableColumns

included Array <optional>

array of included columns indices

excluded Array <optional>

array of excluded columns indices

(static) listenForSort(delegatedTarget, columns, sortOrder)

Source:

sets up listeners for column headers available for click

Parameters:
Name Type Description
delegatedTarget HTMLElement

element that will receive clicks and see if they are valid, thead is recommended to boil down to header clicks only

columns TableColumns

array of table columns from SortTable#defineSortableColumns

sortOrder SortOrder

instance of SortOrder

Listens to Events:
  • event:click

(static) sortDimension(data, columns, sortOrder)

Source:

Splits sorting into one-column or two-column. The precedence of columns in sortOrder is the factor defining sort priority

Parameters:
Name Type Description
data Array

array containing row items to be sorted

columns TableColumns

array of table columns from SortTable#defineSortableColumns

sortOrder SortOrder

instance of SortOrder

(static) sorter()

Source:

Function that performs case insensitive sorting in the array. It can distinguish between numbers, numbers as strings, HTML and plain strings

sort(sortOrder)

Source:

Performs channeling of sorting based on whether this.data is multidimensional

Parameters:
Name Type Description
sortOrder SortOrder

instance of SortOrder passed by the SortOrder#sort on initial sort

Fires:

Events

reportal-table-sort

Source:

Event reporting that a table has been sorted