getQTable()

The getQTable() function (client-side and server-side) provides access to a qTable object, which includes a range of methods for retrieving and modifying cell values, handling rows and columns, and importing data. For more information about qTables, see QTables.

Syntax

Use this syntax for the getQTable() function:

            let qtable = getQTable('QTABLE_QUESTION_CODE'); 

          

Return Value

The getQTable() function returns a qTable object that provides several methods. For more information, see QTable Object Methods.

Parameters

Note:

The QTABLE_QUESTION_CODE parameter is required.

The getQTable() function accept the qTable question code as a string parameter. You can find the code in the Code field on the qTable question record.

QTable Object Methods

You can retrieve and modify qTable data using the methods attached to the qTable object. The following table outlines the methods for the qTable object and their purpose.

Method

Description

getInfo();

Returns an object containing information about enabled or inactive features of the qTable.

getRowCount();

Returns the total number of rows in the qTable.

getFilledRowCount();

Returns the highest row number that contains data. For example, if there are 10 rows in total, and only rows 1, 2, and 7 have data, the function returns 7.

getColumns();

Returns an array of answer codes (columns) used in the qTable.

get('ANSWER_CODE', row);

Retrieves the value of a specific cell using the answer code (column) and row number. Both parameters are required.

setRowCount(number);

Sets the number of rows in the table to the specified number.

set('ANSWER_CODE', row, 'value');

Sets the value of a specific cell identified by the answer code (column) and row number.

  • insert();

  • insert(row);

Inserts a blank row at the specified position by shifting rows down. If no position is provided, the rows is inserted at the bottom of the qTable.

Note:

To insert rows, the Allow row number editing option must be enabled on the qTable question record.

delete(row);

Deletes the row at the specified position by shifting rows up.

Note:

To delete rows, the Allow row number editing option must be enabled on the qTable question record.

clear();

Removes all data from the qTable but keeps the same number of rows.

import(data, map, clear);

Imports data into the qTable, with optional column mapping and data clearing before import.

To specify information for the import() method, see detailed information about its parameters:

Note:

The data parameter is required.

  • data - An array of JavaScript objects. Each row represents a row in the qTable. Each object should include properties that map to qTable answer codes (qTable columns). See an example below:

                    [
      {
            "id": "479",
            "itemid": "FUR00001",
            "displayname": "Desk Wood-Black",
            "cost": "500.00"
        },
        {
            "id": "229",
            "itemid": "CHA00001",
            "displayname": "Deluxe High-Back Tilter",
            "cost": "67.99"
        },
        {
            "id": "253",
            "itemid": "LAM00002",
            "displayname": "Chrome Halogen Desk Lamp",
            "cost": "4.99"
        }
    ] 
    
                  
  • map - An object that maps qTable answer codes (qTable columns) to keys in the data parameter. See the example below:

                    {
        INTERNAL_ID: 'id',
        ITEM_ID: 'itemid',
        NAME: 'displayname',
        PRICE: 'cost'
    } 
    
                  

    If the data object keys match answer codes, map can be omitted. When omitting it, you can use the following syntax formats:

    •                     qtable.import(data); 
      
                        
    •                     qtable.import(data, null, true); 
      
                        
  • clear - A true or false value to determine whether all existing qTable data is cleared before importing new data. This parameter is false by default.

Examples

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

Retrieving Table Info

This example retrieves qTable information, such as whether manual row numbering and cell editing are allowed.

              let info = qtable.getInfo();
console.log(info) 

            

The resulting output may look like this:

              {
    dynRows: true,
    manualEdit: false
} 

            

Retrieving Column Codes

This example retrieves the answer codes (qTable columns) present in the qTable.

              let columns = qtable.getColumns();
console.log(columns); 

            

The resulting output may look like this:

              ["INTERNAL_ID", "ITEM_ID", "NAME", "PRICE"] 

            

Retrieving a Cell Value

This example retrieves the cell value with answer code (qTable column) ITEM_ID in row 3.

              let name = qtable.get('ITEM_ID', 3); 

            

Setting a Cell Value

In this example, the item name with the answer code NAME in row 3 is updated using the specified value. NAME is a qTable column.

              qtable.set('NAME', 3, 'Desktop A1000 - Series C'); 

            

Related Topics

General Notices