Skip to content
This repository was archived by the owner on May 30, 2021. It is now read-only.
Karl edited this page Sep 3, 2017 · 30 revisions

Please note that the API is not finalised and may change so check back once in while.

table

type Object

Returns a reference to the HTMLTableElement.


head

type Object

Returns a reference to the HTML <thead> element.


body

type Object

Returns a reference to the HTML <tbody> element.


foot

type Object

Returns a reference to the HTML <tfoot> element.


wrapper

type Object

Returns a reference to the main HTMLDivElement that wraps the entire layout.


container

type Object

Returns a reference to the main HTMLDivElement that contains the table.


pagers

type Array

Returns a reference to the currently displayed pagers.


headings

type HTMLCollection

Returns a live HTMLCollection of the the table headings.


options

type Object

Returns the current configuration options.


initialized

type Boolean

Returns true if the library is fully loaded and all HTML is rendered.


isIE

type Boolean

Returns true if the current browser is a version of MS Internet Exporer or MS Edge.


data

type Array

Returns a collection of all HTMLTableRowElements in the table.


pages

type Array

Returns a collection of pages each of which contain collections of HTMLTableRowElements.


hasRows

type Boolean

Returns true if the current table has rows.


hasHeadings

type Boolean

Returns true if the current table has headings.


currentPage

type Integer

Returns the current page number.


totalPages

type Integer

Returns then number of pages.


onFirstPage

type Boolean

Returns true if the current page is also the first page.


onLastPage

type Boolean

Returns true if the current page is also the last page.


searching

type Boolean

Returns true if a search is currently being done and search results are displayed.


searchData

type Array

Returns a collection of HTMLTableRowElements containing matching results.


export(options [object])

type Function

Export the table data to various formats.

The options argument must be an object of which the only required property is the type property which accepts either csv, txt, json or sql as it's value. The rest are optional:

{
    download: true, // trigger download of file or return the string
    skipColumn: [], // array of column indexes to skip

    // csv
    lineDelimiter:  "\n", // line delimiter for csv type
    columnDelimiter:  ",", // column delimiter for csv type

    // sql
    tableName: "myTable", // SQL table name for sql type

    // json
    replacer: null, // JSON.stringify's replacer parameter for json type
    space: 4 // JSON.stringify's space parameter for json type
};

Examples

// Export the current page as a .csv file
dataTable.export({
    type: "csv",
    filename: "my-csv-file"
    selection: dataTable.currentPage
});
// Export pages 1-5 as an .sql file
dataTable.export({
    type: "sql",
    tableName: "sql_users",
    selection: [1,2,3,4,5]
});
// Export to .json file
dataTable.export({
    type: "json",
});
// Export to json string, omitting the 1st, 3rd and 5th columns
dataTable.export({
    type: "json",
    skipColumn: [0,2,4],
    download: false // return formatted string instead of file
});

import(options [object])

type Function

Import data into the table from json or csv strings.

The options argument must be an object of which the only required properties are data and type. The data property should be the csv or json string and the type property should indicate the type of data being imported - csv or json.

{
    type: "csv" // or "json"
    data: // the csv or json string

    // csv
    lineDelimiter:  "\n", // line delimiter for csv type
    columnDelimiter:  ",", // column delimiter for csv type
};
    // Import a csv string
    datatable.import({
        type: "csv",
        data: "Heading 1|Heading 2|Heading 3,Value 1|Value 2|Value 3,Value 4|Value 5|Value 6".
        lineDelimiter:  ",",
        columnDelimiter:  "|"
    });

Note that whilst checks are performed for valid json strings, none are present for csv checking so it's up to you to make sure the formatting is correct.


print()

type Function

Display printable version.


Clone this wiki locally