Introduction


This namespace is helpful when working with table. You can add rows, move rows between tables and even remove rows.


HTML Tables and Datatables


All functions listed bellow works with both html tables and Datatables. You don't need to specify what you are using html tables or Datatables. Spacer automatically detects what table you using.


Row Object Structure


In this namespace you can add rows by passing row object (when adding single row) or array of row object (when adding multiple rows). In both cases the row object structure is as follow:

{
    id: 'idForRow',
    class: 'classForRow',
    attr: {key1: 'value1', key2: 'value2'},
    columns: [
        {
            id: 'idForColumnData',
            class: 'classForColumnData',
            attr: {key3: 'value3', key4: 'value4'},
            data: '',
        },
        {... another column ...},
        {... another column ...},
    ],
}

id, class and attr are optional attributes to set the id, class and attr respectively for both row and column data.


Functions



spa.table.addRows(table, rows)


Add new row(s) to table.

Parameter Type Description
table string | JQuery Table as jQuery selector string or as JQuery object
rows object | array Row object or array of row objects

spa.table.removeRows(table, rows)


Remove row(s) from table.

Parameter Type Description
table string | JQuery Table as jQuery selector string or as JQuery object
rows string | JQuery Row(s) as jQuery selector string or as JQuery object.

spa.table.removeChecked(table, inputName)


Remove checked row(s) from table.

Parameter Type Description
table string | JQuery Table as jQuery selector string or as JQuery object
inputName string Checkbox input name.

spa.table.removeAll(table)


Remove all rows from table.

Parameter Type Description
table string | JQuery Table as jQuery selector string or as JQuery object

spa.table.moveRows(from, to, rows)


Move row(s) from table ot another.

Parameter Type Description
from string | JQuery Table as jQuery selector string or as JQuery object
to string | JQuery Table as jQuery selector string or as JQuery object
rows string | JQuery Row(s) as jQuery selector string or as JQuery object

spa.table.moveChecked(from, to, inputName)


Move checked row(s) from table ot another.

Parameter Type Description
from string | JQuery Table as jQuery selector string or as JQuery object
to string | JQuery Table as jQuery selector string or as JQuery object
inputName string Checkbox input name

spa.table.count(table, rows)


Get rows count.

Parameter Type Description
table string | JQuery Table as jQuery selector string or as JQuery object
rows string | JQuery Optional parameter. If it's not set, the function return the total row count. If it's set, the function return specified rows count. For example, to get the count of all row that has child class in the table with id myTable: spa.table.count('#myTable', '.child')

spa.table.updatePaginationTotal(value, rowCountElement)


This function expects row count element with class total inside element with id pagination. This function add value to the old row count. This function is called automatically after previous functions that add or remove rows.

Parameter Type Description
value integer Value to be added to row count. use positive value to add up, or negative value to subtract
rowCountElement string | JQuery Row count element as jQuery selector string or as JQuery object