Data Tables

Data Tables

The DataTables plugin uses a jQuery JavaScript library to transform a HTML table to an advanced table; providing features such as search capability, paginated results, and column sorting.

Centralpoint generates two type of sources: Static and Dynamic.

Static

This method connects to an existing Data Source and applies the DataTable plugin to the table HTML in the Formatting tab of the Data Source record.

This method provides more flexibility with the table HTML format, but the disadvantage is that it retrieves the entire data set on the initial page load. The plugin hides a majority of the records retrieved and lets you search and paginate through the results.

The Static option works very similar to the original ExtTable CpScript, except that the HTML binds to the newer version of the DataTable plugin.

In the Formatting Tab you have Styles, Scripts, Template and Data Source Attributes.

Styles are used to add any custom styles to the page where Data Table will be displayed.

Scripts will add custom JavaScript to the page.

The Template attribute is used to format the table's HTML The placeholder CpScript will get populated with the DataSource content.[cp:literal:placeholders key='DataSource' /]


Dynamic:

This method uses an AJAX model to call a Web API which returns JSON. The DataTable plugin uses the JSON result to generate the table's format.

This method has less formatting flexibility, but works great with larger data sets because it only retrieves (n) number of records at a time. Each time the result set changes by user's interacting with the table's search, pagination, or sorting; the Web API is called to return an updated result set.

The initial ordering of the results is based on data in the first column. The DataTable plugin only allows ordering and sorting on by columns which are in relation of the module.

Another performance benefit to the Dynamic option is that the search is executed through a server-side Full-Text Index search compared to a client-side text search that the Static option uses.

When a record is saved in the Data Table module, a corresponding Web API module record will be created or updated if the type attribute is set to Managed.

The corresponding Web API record name will be formatted as shown here: DataTables (Managed) - <<Name of the Data Table record>>

If the type attribute is set to Detached then you have to manage your Web API record manually. The order of the columns in Data table records and in WebApi has to match. The columns which are in webApi but not in DataTable have to be at the end of the Columns in WebApi record same as hidden columns.

* If you creating API record manually make sure the Result is set to Object

Formatting Tab

The Formatting Tab provides the following attributes: Custom Control, Styles, Scripts, and Template.

Custom Control

This control provides a user interface to configure and retrieve data for dynamic option.

  • The Hide/Show Available Columns link will display all available columns for the selected module.

    Columns prefixed with cpsys_Attributes: are not in the table's relation and can't be used for the sorting.

  • Add Column Button will add new row with the selector of columns.

    When you select the standard column option, the column names will be used in the table header as is.

    One of the options in the selector is custom. When this option is selected you have control over the column names in the table header, and you may use Column CpScripts to retrieve content for that column.

    The check box next to the row is to display that column in the table. Sometimes you may need to retrieve a column, but don't want to display the column on your page. In this case you may uncheck a checkbox and the column will not be displayed in the table. You can drag and drop rows to arrange the order of the table header.

    To the right of the row there is a delete icon which would remove that row from data table.

Supported Scripts:

  • ColumnFriendlyUrl: (script can be used to build the URL.)

    <a href="[cp:literal:scripting key='ColumnFriendlyUrl' audiencesystemname='audience-1' systemname='genericv' /]">[cp:literal:scripting key='Column' name='Title' /]</a>
  • Column: (script can be used to get value out of Columns and apply formatting.)

    [cp:literal:scripting key='Column' name='StartDate' truncate='' defaultValue='' format='{0:MM-dd-yyyy h:mm tt}' DataType='DateTime' /]

Dynamic Types

  • Managed: This type will generate or update a corresponding Web API record each time the Data Tables module record is saved.

    **Important** Due to the behavior applied when "Managed" is selected, you will not be able to manually edit the corresponding Web API record. This is because manual changes made to the Web API record will be overwritten each time the Data Table record is saved.

  • Detached: This type provides flexibility to format and customize the corresponding Web API record.

    **Important** This option should only be applied and managed by advanced users.


Data Tables plugin options: Work with both options Static and Dynamic types.

Minimum Number Of Characters:

How many characters need to be typed before search will be executed

Page Length:

Number of rows to display on a single page when using pagination. Default: 10

Search Enabled:

Enable or disable search (filtering) abilities.

Pagination Enabled:

Enable or disable table pagination

Sort Enabled:

Enable or disable ordering of columns

Length Menu:

Parameter allows you to readily specify the entries in the length drop down select list that DataTables shows when pagination is enabled. Will let user to change number of records display per page.

Number of Pages in Pagination:

Number of pages control presented for pagination (forward and backward buttons with up to (n) page numbers in-between)

Scroll Vertical:

If enabled DataTables table body scrolling in the vertical direction.

Container Height attribute let you set Height in px or in vh(viewpoint height)


You can pass any information from the page DataTable page onto the API. In order to do that you need to set the global Javascript variable _dataTablePageInformation with JavaScript object (key-value pairs).
Example:
 var pageInfo = {
   PageAudience: "Main",
   UserName: "development",
   Roles: "Admin"
 };

_dataTablePageInformation = pageInfo;
 
Then you can use that information in the API by getting it from the placeholders.
Example:
[cp:literal:placeholders key='PageAudience' /]