createTable()

The createTable() function (client-side and server-side) creates a script-generated table using the table code. If you pass the code of an existing table, the function returns it as a table object using getTable().

Syntax

Use this syntax for the createTable() function:

            createTable('TABLE_CODE'); 

          

Return Value

The createTable() function returns an object. This object includes the tableRef property, which contains information about the table record:

  • id

  • code

  • type

  • status

  • content

The returned object also provides methods for setting, retrieving, and updating table data, as well as changing the table status and loading content. The following table outlines the methods provided by the returned object.

Method

Description

set(content)

Updates the entire table content.

set(row, columnValue)

Sets the values for an entire row. columnValue is an object used to specify the value for each column.

set(row, column, value)

Sets the value of a specific cell.

get()

Returns the entire table content as an array of rows.

get(row)

Returns the entire row.

get(row, column) - Returns the value of a cell.

Returns the value of a cell.

importObj(data, mapping)

Imports data from an object into a two-column table using key-value mappings. The mapping parameter is an object with the following format:

                      {key: 'KeyColumnName', value: 'ValueColumnName'} 

                    

setStatus(status)

Changes the table status. The available statuses are ready. empty, error, and loading.

                      loadContent({
    filter: ['fieldID1', 'operator', 'value1'],
    async: true | false
}).done(callback)
  .fail(callback); 

                    
Note:

This method is available for dynamic tables only.

Loads table content from the database. This method returns a promise that resolves to an object containing the table content. The filter property is required, and async defaults to true.

Parameters

The createTable() function accepts the table code in string format ('TABLE_CODE') as a required parameter. For existing tables, you can find the code in the Code field on the table record.

Examples

The following examples show how to use the createTable() function.

Retrieving or Creating a Table

This example calls createTable() to retrieve a table with the code LAPTOPS. If the table doesn't exist, the function will create it.

              const laptopsTable = createTable('LAPTOPS'); 

            

Related Topics

General Notices