Class: SelectorTable

SelectorTable

The SelectorTable object, a displayable table with a radio button column and optional paging.

new SelectorTable()

Source:

Methods

addDiv(row, col, val, width)

Insert a span into a column of the table for later use (e.g., as a graphic element)
Parameters:
Name Type Description
row number The row of interest, zero being first tbody row
col number The column of interest
val string The name base of the span, to which we append the row
width string Optional width specifier
Source:

addHeader()

Adds a header to the table. Uses the anonymous argument array as input, so no declared args.
Source:

addRow() → {integer}

Adds a data row to the table. Uses the anonymous argument array as input, so no declared args.
Source:
Returns:
row index added.
Type
integer
Example
myTable.addRow('ken','707-555-1212','ken@calast.com');

addRowWithValue() → {integer}

Adds a data row to the table. Uses the anonymous argument array as input, so no declared args. The first argument is not displayable, but is assigned to the radio button as a value.
Source:
Returns:
row index added.
Type
integer
Example
myTable.addRowWithValue(42,'ken','707-555-1212','ken@calast.com');

appendTo(parent)

Appends the table and page block to a parent node
Parameters:
Name Type Description
parent Object The DOM element to which this is added
Source:

deleteData()

Delete all data rows from the table. Primarily used when redrawing a table that is already part of a view, keeping its header intact. Deletes all children of the tbody node.
Source:

enablePaging(listener)

Turn paging on for this object
Parameters:
Name Type Description
listener function An event listener to be called when user clicks on prev and next buttons
Source:

getDataValue(row, col) → {mixed}

Get the contents of one data element for a specified row and column
Parameters:
Name Type Description
row number The row of interest, zero being first tbody row
col number The column of interest
Source:
Returns:
The 'td' value at that row and column or null if not found
Type
mixed

getHeaderValue(row, col) → {mixed}

Get the contents of one header element for a specified row and column
Parameters:
Name Type Description
row number The row of interest, zero being first thead row (usually only one)
col number The column of interest
Source:
Returns:
The 'th' value at that row and column or null if not found
Type
mixed

getInnerText(el) → {String}

This function retrieves the text in a DOM-independent way
Parameters:
Name Type Description
el Object The DOM element whose text content is to be retrieved
Source:
Returns:
Text contents of the table cell
Type
String

getRowCount() → {number}

Returns the number of rows that have been added to the table
Source:
Returns:
The row count
Type
number

getRowValue(row) → {mixed}

Get the value of the button of the specified row. Requires use of addRowWithValue.
Parameters:
Name Type Description
row number The data row of interest, NOT the one selected.
Source:
Returns:
The value of the selector button, or null if nonexistent.
Type
mixed

getSelected(autoselect) → {number}

Get the index of the currently selected row, zero being first tbody row
Parameters:
Name Type Description
autoselect Boolean Optional control of automatic selection of first row if only one present; default true
Source:
Returns:
The row index, or null if no row is selected.
Type
number

getSelectedColumn(col) → {array}

Get the contents of one table element from the currently selected row
Parameters:
Name Type Description
col number The column of interest
Source:
Returns:
The 'td' value at that row and column, null if nonexistent
Type
array

getSelectedValue(autoselect) → {mixed}

Get the value of the button of the currently selected row. Requires use of addRowWithValue.
Parameters:
Name Type Description
autoselect Boolean Optional control of automatic selection of first row if only one present; default true
Source:
Returns:
The value of the selector button, or null if no row is selected.
Type
mixed

hideRow()

Hide a specific row of the table
Source:

hideUnselected()

Change the display attribute for all rows except the selected one to hidden.
Source:

makeSortable()

Make this table sortable - must be called after table has its contents Although most of the code for this method is original, many of the design ideas were inspired by examples at http://www.webtoolkit.info/, and much credit is due to the author(s) of that site.
Source:

nextPage()

Display the next page of the table; called from event listener.
Source:

onClick(listener)

Add an (optional) event listener to every radio button - must be called AFTER rows have been added. Originally added listener to every input, but works more reliably if the first input per row is used.
Parameters:
Name Type Description
listener function The function to be called when the user clicks on a radio button
Source:

prevPage()

Display the previous page of the table; called from event listener.
Source:

refreshPage()

Does the actual display; called from showPage, nextPage, or prevPage
Source:

rowIsDisplayed()

Return display state of specified row
Source:

setCellClass(row, col, style)

Set the class for a cell
Parameters:
Name Type Description
row number The row of interest
col number The column of interest
style string The CSS class name
Source:

setClass(clinfo)

Assigns a CSS class to the table
Parameters:
Name Type Description
clinfo string The CSS class to assign to the table's class attribute
Source:

setColors(normal, selected)

Set the background colors for the table object
Parameters:
Name Type Description
normal mixed The color to use for the non-selected rows
selected mixed The color to use for the selected row
Source:

setColumnClass(col, style)

Set the class for a column
Parameters:
Name Type Description
col number The column of interest
style string The CSS class name
Source:

setDataValue(row, col, val)

Set the contents of one data element by specified row and column
Parameters:
Name Type Description
row number The row of interest, zero being first tbody row
col number The column of interest
val number The new value
Source:

setInputElement(row, col, val)

Replace the contents of specified row and column with an input element, and give the element the class inputElement in addition to any classes it already has.
Parameters:
Name Type Description
row number The row of interest, zero being first tbody row
col number The column of interest
val string The new value (an input element)
Source:

setPageSize(sz)

Set the number of table rows per page
Parameters:
Name Type Description
sz number The number of rows per page
Source:

setSelected()

Select the specified row, if possible
Source:

setTextColor(row, col, selected)

Set the text color for one table element
Parameters:
Name Type Description
row number The row of interest, zero is first tbody row
col number The column of interest
selected mixed The color to use for the selected element
Source:
Returns:
true if the row and column were found, false otherwise

showPage(pagenum)

Display a specific page of the table; called from event listener.
Parameters:
Name Type Description
pagenum number Which page to display
Source:

sort(cell)

This function does the actual sort
Parameters:
Name Type Description
cell Object The DOM element that actually got clicked on
Source:

sortAlpha(a, b) → {Number}

This function does a sort compare of two alpha fields in a case-independent way
Parameters:
Name Type Description
a Object First DOM element
b Object Second DOM element
Source:
Returns:
0 if equal, 1 if a > b, -1 if a < b
Type
Number

sortNumeric(a, b) → {Number}

This function does a sort compare of two numeric fields
Parameters:
Name Type Description
a Object First DOM element
b Object Second DOM element
Source:
Returns:
0 if equal, 1 if a > b, -1 if a < b
Type
Number

updateRowWithValue((anonymous))

Finds a row by button value, changes other columns. Uses the anonymous argument array as input, so no declared args except the value string identfying the button.
Parameters:
Name Type Description
(anonymous) Array.<String> First element is value to find, rest are replacement values
Source:
Example
myTable.updateRowWithValue(42,'bob','707-555-1213','keng@calast.com');