Beta Release - This version is currently under development and should not be used in a production environment.

Component Objects

Overview

Component objects are a key feature of Tabulator, that allow you to interact directly with the components of your table.

There is a component object for each row, column, cell and row group in your table. Each component provides a range of functions you can call to manipulate the table.

Components are passed into almost every callback available in Tabulator.

Component Types

Row Component

The row component provides access to a specific row. The example below shows how it is passed to the rowFormatter callback:

var table = new Tabulator("#example-table", {
    rowFormatter:function(row){
        var data = row.getData(); //get data object for row

        if(data.col == "blue"){
            row.getElement().css({"background-color":"#A6A6DF"}); //apply css change to row element
        }
    },
});

The component provides the following functions:

Get Data

The getData function returns the data object for the row.

var rowData = row.getData();

Get Element

The getElement function returns the DOM node for the row.

var rowElement = row.getElement();

Get Table

The getTable function returns the Tabulator object for the table containing the row.

var table = row.getTable();

Get Cells

The getCells function returns an array of CellComponent objects, one for each cell in the row.

var cells = row.getCells();

Get Cell in Specific Column

The getCell function returns the CellComponent for the specified column from this row.

var cells = row.getCell(column);

Get Index

The getIndex function returns the index value for the row. (this is the value from the defined index column, NOT the ros position in the table)

var rowIndex = row.getIndex();

Get Position

Use the getPosition function to retreive the numerical position of a row in the table. By default this will return the position of the row in all data, including data currently filtered out of the table.

If you want to get the position of the row in the currently filtered/sorted data, you can pass a value of true to the optional first argument of the function.

var rowPosition = row.getPosition(true); //return the position of the row in the filtered/sorted data

Get Group

When using grouped rows, you can retreive the group component for the current row using the getGroup function.

var group = row.getGroup();

Delete

The delete function deletes the row, removing its data from the table

row.delete();

Scroll To

The scrollTo function will scroll the table to the row if it passes the current filters.

row.scrollTo();

Update

You can update the data in the row using the update function. You should pass an object to the function containing any fields you wish to update. This object will not replace the row data, only the fields included in the object will be updated.

row.update({"name":"steve"}); //update the row data for field "name"

Select

The select function will select the current row.

row.select();

Deselect

The deselect function will deselect the current row.

row.deselect();

Toggle Selection

The toggleSelect function will toggle the selected state the current row.

row.toggleSelect();

Check Selection State

The istSelected function will return a boolean representing the current selected state of the row.

var selected = row.istSelected();

Normalize Height

If you are making manual adjustments to elements conained within the row, it may sometimes be necessary to recalculate the height of all the cells in the row to make sure they remain aligned. Call the normalizeHeight function to do this.

row.normalizeHeight();

Re-Format

If you want to re-format a row once it has been rendered to re-trigger the cell formatters and the rowFormatter callback, Call the reformat function.

row.reformat();

Freeze

You can freeze a row at the top of the table by calling the freeze function. This will insert the row above the scrolling portion of the table in the table header.

row.freeze();

Unfreeze

A frozen row can be unfrozen using the unfreeze function. This will remove the row from the table header and re-insert it back in the table.

row.unfreeze();

Column Component

The column component provides access to a specific column. The example below shows how it is passed to the columnMoved callback.

var table = new Tabulator("#example-table", {
    columnMoved:function(column, columns){
        alert("The user has moved column: " + column.getField()); //display the columns field name
    }
});

The component provides the following functions:

Get Element

The getElement function returns the DOM node for the column.

var columnElement = column.getElement();

Get Table

The getTable function returns the Tabulator object for the table containing the column.

var table = column.getTable();

Get Definition

The getDefinition function returns the column defintion object for the column.

var columnDefinition = column.getDefinition();

Get Field

The getField function returns the field name for the column.

var columnField = column.getField();

Get Cells

The getCells function returns an array of CellComponent objects, one for each cell in the column.

var cells = column.getCells();

Get Visibility

The getVisibility function returns a boolean to show if the column is visible, a value of true means it is visible.

var visible = column.getVisibility();

Show Column

The show function shows the column if it is hidden.

column.show();

Hide Column

The hide function hides the column if it is visible.

column.hide();

Toggle Visibility

The toggle function toggles the visibility of the column, switching between hidden and visible.

column.toggle();

Delete

The delete function deletes the column, removing it from the table

column.delete();

Scroll To

The scrollTo function will scroll the table to the column if it is visible.

column.scrollTo();

Get Sub Columns

The getSubColumns function returns an array of ColumnComponent objects, one for each sub column of this column.

var subColumns = column.getSubColumns();

Get Parent Column

The getParentColumn function returns the ColumnComponent for the parent column of this column. if no parent exists, this function will return false

var parentColumn = column.getParentColumn();

Focus on Header Filter

The headerFilterFocus function will place focus on the header filter element for this column if it exists.

column.headerFilterFocus();

Set Header Filter Value

The setHeaderFilterValue function set the value of the columns header filter element to the value provided in the first argument.

column.setHeaderFilterValue("steve");

Reload Header Filter Element

The reloadHeaderFilter function rebuilds the header filter element, updating any params passed into the editor used to generate the filter.

column.reloadHeaderFilter();

Cell Component

The cell component provides access to a specific cell. The example below shows how it is passed to the cellClick callback for a cell.

{title:"Name", field:"name", cellClick:function(e, cell){
        alert("The cell has a value of:" + cell.getValue()); //display the cells value
    },
}

The Component provides the following functions:

Get Value

The getValue function returns the current value for the cell.

var cellValue = cell.getValue();

Get Old Value

The getOldValue function returns the previous value of the cell. Very usefull in the event of cell update callbacks.

var cellOldValue = cell.getOldValue();

Restore Old Value

The restoreOldValue reverts the value of the cell back to its previous value, without triggering any of the cell edit callbacks.

cell.restoreOldValue();

Get Element

The getElement function returns the DOM node for the cell.

var cellElement = cell.getElement();

Get Table

The getTable function returns the Tabulator object for the table containing the cell.

var table = cell.getTable();

Get Row

The getRow function returns the RowComponent for the row that contains the cell.

var row = cell.getRow();

Get Column

The getColumn function returns the ColumnComponent for the column that contains the cell.

var column = cell.getColumn();

Get Data

The getData function returns the data for the row that contains the cell.

var data = cell.getData();

Get Field

The getField function returns the field name for the column that contains the cell.

var field = cell.getField();

Set Value

You can change the value of the cell using the setValue function. The first parameter should be the new value for the cell, the second optional parameter will apply the column mutators to the value when set to true (default = true).

cell.setValue("Steve", true); //set the cell's value to "Steve" and apply the column mutators if present

Check Height

If you are making manual adjustments to elements contained withing the cell, or the cell itself, it may sometimes be necessary to recalculate the height of all the cells in the row to make sure they remain aligned. Call the checkHeight function to check if the height of the cell has changed and normalize the row if it has.

cell.checkHeight();

Edit

You and programatically cause a cell to open its editor element using the edit function.

cell.edit();

If you want to ignore the editable property of the column definition and force the edit, you can pass an optional value of true to the function

cell.edit(true); //force the editor to open even if editable is set to false

Cancel Edit

You and programatically cancel a cell edit that is currently in progress by calling the cancelEdit function.

cell.cancelEdit();

Navigation

When a cell is being edited it is possible to move the editor focus from the current cell to one if its neighbours. There are a number of functions that can be called on the nav function to move the focus in different directions.

cell.nav().left(); //move focus left to next editable cell.

You can navigat any direction around the table using the following functions:

  • prev - next editable cell on the left, if none available move to the right most editable cell on the row above
  • next - next editable cell on the right, if none available move to left most editable cell on the row below
  • left - next editable cell on the left, return false if none available on row
  • right - next editable cell on the right, return false if none available on row
  • up - move to the same cell in the row above
  • down - move to the same cell in the row below

Group Component

The group component provides access to a set of grouped rows. The example below shows how it is passed to the groupVisibilityChanged callback.

var table = new Tabulator("#example-table", {
    groupVisibilityChanged:function(group, visible){
        alert("The user has " (visible ? "opened" : "collapsed") +" group: " + group.getKey()); //display the groups unique key
    }
});

The component provides the following functions:

Get Element

The getElement function returns the DOM node for the gruop header.

var groupElement = group.getElement();

Get Table

The getTable function returns the Tabulator object for the table containing the group.

var table = group.getTable();

Get Key

The getKey function returns the unique key that is shared between all rows in this group.

var key = group.getKey();

Get Rows

The getRows function returns an array of RowComponent objects, one for each row in the group.

var rows = group.getRows();

Get Sub Groups

The getSubGroups function returns an array of GroupComponent objects, one for each sub group of this group.

var subGroups = group.getSubGroups();

Get Parent Group

The getParentGroup function returns the GroupComponent for the parent group of this group. if no parent exists, this function will return false

var parentGroup = group.getParentGroup();

Get Visibility

The getVisibility function returns a boolean to show if the group is visible, a value of true means it is visible.

var visible = group.getVisibility();

Show Group

The show function shows the group if it is hidden.

group.show();

Hide Group

The hide function hides the group if it is visible.

group.hide();

Toggle Visibility

The toggle function toggles the visibility of the group, switching between hidden and visible.

group.toggle();

Component Lookup

Any function that takes a component as an argument will also attempt to find that component based on the value provided if it is not a component iteslf. The following values can be used for each copmonent type:

Row

  • A RowComponent
  • The index value of the row
  • DOM node of the row

Column

Cell