List


Intro

List View is a component in Activator designed to display dynamic data in an HTML table. It leverages the JavaScript DataTable component to provide a robust and streamlined solution for efficiently presenting and managing large amounts of data. By utilizing a specified data source, the List View simplifies the implementation of interactive and responsive tables while offering advanced features such as sorting, pagination, and search. This component optimizes data display while reducing development time required for creating interactive tables.

Graphic example

Rendu composant list.png
List UI

Structurally, once interpreted, a list renders like the image above. However, let's highlight the different structures that make up the List component

List

The breakdown reveals nine main parts:

  1. List icon
  2. Title List
  3. Button to change list view
  4. Search bar to find an element in the view
  5. button to collapse the list. The idea is to collapse the list container in order to create another container to display more details about an element in a list view.
  6. Buttons a actions for a list view.
  7. Line for the titles of each column.
  8. list view element container
  9. view list header.

    Before going into detail about the various structures resulting from the decomposition of a ListView (illustrated in the image above ☝️), let's start by focusing on the creation of a List component on Activator Admin🤫.

 

Creation

The creation of List View components on Activator Admin allows us to build a visual representation of a data collection on several views. This user interface widget is managed by four main components:

  1. List View: Contains the definition of the main elements of the table, including views and action buttons.
  2. List View Driver: Manages behaviors and events related to the List View.
  3. View: Defines the main view by binding the data source, arranging the columns, and managing security privileges.
  4. View Driver: Customizes the view and handles behaviors for events and actions in the List View.

 

List View

This is the main component responsible for defining the main elements of the data table, such as the different views taken into account, the different action buttons, etc.

 

Creation

In Activator Admin , the List view component is located within the menu container, among the items listed under List📑. As shown at (1) on the image below.

 

NB🚨: Make sure you are in the System Component main module.

 

List View
List View

After initiating the creation of the List view, by clicking on the +Add new button (illustrated at (2) on the image above), you’ll observe a form (illustrated at (3) on the image above) appearing on the right side with some fields.

🔬After filling in the name and description fields, let's focus on the Definition and Meta Data fields.

The Meta Data field gathers and provides additional information for the component, such as configuration and parameters, as well as the accessibility and security measures associated with this component. Please refer to Meta Data for the complete list of additional information related to this component.

As for the Definition field, let's take a closer look at its JSON content.

{
    "resourceName": "",
    "title": "List View",
    "description": "Sample List View",
    "titleResKey": "",
    "descResKey": "",
    "driver": "",
    "icon": "far fa-address-card",
    "views": [
        {
            "name": "",
            "index": 0,
            "visibleFor": {
                "roles": [
                    "sys.everyone"
                ]
            }
        }
    ],
    "buttons": [
        {
            "name": "new",
            "index": 0,
            "title": "New",
            "titleResKey": "",
            "icon": "tio-add",
            "options": [],
            "visibleFor": {
                "roles": [
                    "sys.everyone"
                ]
            }
        },
        {
            "name": "options",
            "index": 1,
            "title": "Options",
            "titleResKey": "",
            "icon": "tio-more-vertical",
            "options": [
                {
                    "id": "option1",
                    "title": "Option 1",
                    "icon": "fas fa-edit",
                    "visibleFor": {
                        "roles": [
                            "sys.everyone"
                        ]
                    }
                },
                {
                    "id": "option2",
                    "title": "Option 2",
                    "icon": "fas fa-edit",
                    "visibleFor": {
                        "roles": [
                            "sys.everyone"
                        ]
                    }
                }
            ],
            "visibleFor": {
                "roles": [
                    "sys.everyone"
                ]
            }
        }
    ]
}

 

Description

PROPERTY REQUIREDDEFAULT VALUEDESCRIPTION
resourceNameYes""Represents the associated language resource.
titleNolist viewList view title.
descriptionNoSimple list viewList view description
titleResKeyNo""Resource language key of the title.
descResKeyNo""Resource language key for the description.
driverYes""This is the list view driver
iconNofar fa-address-cardlist view icon
viewYes
[
    {
        "name": "",
        "index": 0,
        "visibleFor": {
            "roles": [
                "sys.everyone"
            ]
        }
    }
]

It is used to define the different views (or perspectives) that will be available in the List View.

  • name: Identifies each view with a unique name
  • index: Defines display order for multiple views.
  • visibleFor: Defines the roles or users authorized to access this view.
buttonsNo
[
    {
        "name": "new",
        "index": 0,
        "title": "New",
        "titleResKey": "",
        "icon": "tio-add",
        "options": [],
        "visibleFor": {
            "roles": [
                "sys.everyone"
            ]
        }
    },
    {
        "name": "options",
        "index": 1,
        "title": "Options",
        "titleResKey": "",
        "icon": "tio-more-vertical",
        "options": [
            {
                "id": "option1",
                "title": "Option 1",
                "icon": "fas fa-edit",
                "visibleFor": {
                    "roles": [
                        "sys.everyone"
                    ]
                }
            },
            {
                "id": "option2",
                "title": "Option 2",
                "icon": "fas fa-edit",
                "visibleFor": {
                    "roles": [
                        "sys.everyone"
                    ]
                }
            }
        ],
        "visibleFor": {
            "roles": [
                "sys.everyone"
            ]
        }
    }
]

It is used to define the action buttons available in the List View, allowing users to interact with the data displayed in the table. Each button can represent a specific action or a group of options, and their behavior as well as their visibility can be customized.

name: Unique name of button.

index: Defines the order in which the button is displayed in the user interface.

title:  Specifies the text to be displayed on the button, for example, “New” or “Options”.

titleResKey: language resource key for title

icon: button icon

options: Lists the options available in a dropdown button. Each option can have its own title, icon, and visibility rules(visibleFor).

 

List View Driver

The List View Driver is an essential component that acts as a controller for the List View. It allows specific behaviors to be attached to various events and actions related to the data table.

 

Creation

In Activator Admin , the List view driver component is located within the menu container, among the items listed under List📑. As shown at (1) on the image below.

 

NB🚨: Make sure you are in the System Component main module.

 

List view driver
List view driver

After initiating the creation of the List view driver, by clicking on the +Add new button (illustrated at (2) on the image above), you’ll observe a form (illustrated at (3) on the image above) appearing on the right side with some fields.

🔬After filling in the name and description fields, let's focus on the Definition and Meta Data fields.

The Meta Data field gathers and provides additional information for the component, such as configuration and parameters, as well as the accessibility and security measures associated with this component. Please refer to Meta Data for the complete list of additional information related to this component.

As for the Definition field, let's take a closer look at its JavaScript content.

$activator.ui.jsmodules.define(function () {
    // Called to initialize the driver
    this.initialize = function (context) {
        return new Promise((resolve, reject) => {
            //this.__ui.on("load", function (args) {
            //});
            //this.__ui.on("rowselected", function (args) {
            //});
            //this.__ui.on("buttonclick", function (args) {
            //});
            resolve();
        });
    };
});w

 

Description

EVENT / FUNCTIONDESCRIPTION
initialize()The initialize() method prepares the component by initializing the necessary configuration. Inside this method, this.__ui is an object that represents the user interface of the List View. The on() method of this.__ui is used to attach events to this interface.
this.__ui.on("load", function (args) {...})this.__ui.on("load", function (args) {...}) is used to listen for the loading event of the List View. This allows an action to be executed as soon as the List View is fully loaded in the interface. args contains information about the event or the state during the loading.
this.__ui.on("rowselected", function (args) {...})The rowselected event is triggered when a user clicks on a row in the table. The code this.__ui.on("rowselected", function (args) {...}) allows retrieving the index or data of the selected row from the args object.
this.__ui.on("buttonclick", function (args) {...})It allows binding a click event to a specific button in the List View. args contains information related to the clicked button (name, ID, etc.), which allows customizing the action based on the button.

 

Note🛑: Logging the arg argument of the above events, we have👇 :

 

EVENTDESCRIPTION
load 
rowSelected 
buttonClick 

 

View

The View component is responsible for managing the detailed definition of a view within the List View. It handles everything from binding the data source to the definition of column layouts, ensuring that the data is displayed accurately and efficiently. Additionally, it takes into account security aspects by managing access privileges, ensuring that only authorized users can view or interact with certain data or features. This component plays a critical role in providing a flexible and secure data presentation layer while maintaining a clean separation between data handling and the user interface.

 

Creation

In Activator Admin , the View component is located within the menu container, among the items listed under List📑. As shown at (1) on the image below.

 

NB🚨: Make sure you are in the System Component main module.

 

View
View

After initiating the creation of the view, by clicking on the +Add new button (illustrated at (2) on the image above), you’ll observe a form (illustrated at (3) on the image above) appearing on the right side with some fields.

🔬After filling in the name and description fields, let's focus on the Definition and Meta Data fields.

The Meta Data field gathers and provides additional information for the component, such as configuration and parameters, as well as the accessibility and security measures associated with this component. Please refer to Meta Data for the complete list of additional information related to this component.

As for the Definition field, let's take a closer look at its Json content.

{
    "resourceName": "",
    "title": "View",
    "description": "A sample View",
    "titleResKey": "",
    "descResKey": "",
    "isCustom": "false",
    "driver": "",
    "dataBinding": {
        "dataSource": ""
    },
    "columns": [
        {
            "name": "firstName",
            "index": 0,
            "title": "First Name",
            "titleResKey": "",
            "dataBinding": {
                "dataMember": "firstName"
            },
            "visibleFor": {
                "roles": [
                    "sys.everyone"
                ]
            }
        },
        {
            "name": "lastName",
            "index": 0,
            "title": "Last Name",
            "titleResKey": "",
            "dataBinding": {
                "dataMember": "lastName"
            },
            "visibleFor": {
                "roles": [
                    "sys.everyone"
                ]
            }
        }
    ]
}

 

Description

PROPERTYREQUIREDDEFAULT VALUEDESCRIPTION
resourceNameYes""Represents the associated language resource.
titleNoviewView title.
descriptionNoA simple viewView description
titleResKeyNo""Resource language key of the title.
descResKeyNo""Resource language key for the description.
isCustomYesfalseIt is used to indicate whether the view is customized or not. When set to false, it means the view is standard and uses the default settings or behaviors defined in the Activator system. On the other hand, when set to true, it means the view has been customized, and specific configurations or behaviors have been applied to this view directly by the user.
driverNo""This is the view driver
dataBindingYes
{
    "dataSource": ""
}
It links data from an external source to the view. It allows specifying the data source and defining how this data should be mapped or connected to the elements of the view.
columnsYes
[
    {
        "name": "firstName",
        "index": 0,
        "title": "First Name",
        "titleResKey": "",
        "dataBinding": {
            "dataMember": "firstName"
        },
        "visibleFor": {
            "roles": [
                "sys.everyone"
            ]
        }
    },
    {
        "name": "lastName",
        "index": 0,
        "title": "Last Name",
        "titleResKey": "",
        "dataBinding": {
            "dataMember": "lastName"
        },
        "visibleFor": {
            "roles": [
                "sys.everyone"
            ]
        }
    }
]

The columns property in the JSON file for creating a view defines the structure of the columns displayed in the List View. Each item in the columns array represents a specific column in the table and contains several properties to customize its behavior and display. Here is a description of the main properties contained in columns:

  • name: This property defines the unique name of the column.
  • index: The index specifies the display order of the column in the table. Columns are displayed in the order defined by their indices, usually starting from 0.
  • title: The title of the column.
  • titleResKey: The resource key for translating the title.
  • dataBinding: This property links the column to a specific member of the data source. It indicates which field from the data source should be displayed in this column.
  • visibleFor:

 

View Driver

The View Driver component allows for detailed customization of a List View by adjusting its appearance and behavior. It provides the ability to modify specific elements of the view, such as the column layout, visual styles, or the addition of interactive features. In addition to customizing the view, the View Driver enables the attachment of behaviors to various events and actions related to the List View, such as clicks on rows or buttons, using events similar to those defined in the List View Driver.

 

Creation

In Activator Admin , the View component is located within the menu container, among the items listed under List📑. As shown at (1) on the image below.

 

NB🚨: Make sure you are in the System Component main module.

 

View driver
View Driver

After initiating the creation of the view driver, by clicking on the +Add new button (illustrated at (2) on the image above), you’ll observe a form (illustrated at (3) on the image above) appearing on the right side with some fields.

🔬After filling in the name and description fields, let's focus on the Definition and Meta Data fields.

The Meta Data field gathers and provides additional information for the component, such as configuration and parameters, as well as the accessibility and security measures associated with this component. Please refer to Meta Data for the complete list of additional information related to this component.

As for the Definition field, let's take a closer look at its JavaScript content.

$activator.ui.jsmodules.define(function () {

    // Called to initialize the driver
    this.initialize = function (context) {
        return new Promise((resolve, reject) => {
            //this.__ui.on("load", function (args) {
            //
            //});
            //this.__ui.on("columnDataBind", function (args) {

            //
            //});
            //this.__ui.on("columnDataBind", function (args) {

			//
            //});
            resolve();
        });
    };

    //Render the content
    this.render = function (context) {
        return new Promise((resolve, reject) => {
            resolve();
        });
    };


    //Builds the data source arguments
    this.buildDataSourceArgs = function (context) {
        return new Promise((resolve, reject) => {

            //for stored functions
            //resolve({
            //    arguments: []
            //});

            //for stored queries
            resolve({
                parameters: []
            });
        });
    };

});

 

View Driver Configuration

 

NB🚨: The context provided as an argument in the following list of events encompasses both the information passed during the instantiation of the List View and the current contextual data related to the user interface of the view.

  • initialize() 

    View initialization.

    Inside, we can access the property this.__ui, which allows us to listen to and attach different behaviors to events such as:

EVENTSDESCRIPTION
this.__ui.on("load", function (args) {...})Action triggered when the List View is initialized. This event is used to execute tasks during the loading phase of the List View, such as setting up additional configurations or fetching data from external sources.
this.__ui.on("columnDataBind", function (args) {...})

Allows developers to manipulate data and customize the display of each column in the table. Developers can use a switch case to return an object like { skip: true, value: valueOfTheCell }, where skip determines whether the value should be skipped, and value represents the content to display in the cell.

Example:

// Attach the `columnDataBind` event to customize the display of columns.
this.__ui.on('columnDataBind', function (args) {
    // Retrieve column information and data related to the current record.
    const columnName = args?.column?.columnName; // Name of the column
    const record = args?.record; // Data of the current row

    // Validate the data before proceeding
    if (!columnName || !record) return;

    // Customization based on the column name
    switch (columnName) {
        case 'name': // "name" column
            return {
                skip: true, // Skip the default rendering
                value: `${record.firstName} ${record.lastName}`, // Display first and last name
            };

        case 'city': // "city" column
            return {
                skip: true,
                value: record.city || '-', // Display the city or "-" if no data
            };

        case 'country': // "country" column
            return {
                skip: true,
                value: record.country || '-', // Display the country or "-" if no data
            };

        default:
            return; // Do nothing for unspecified columns
    }
});

this.__ui.on("rowDataBind", function (args) {...})

Enables developers to manipulate data and customize the appearance of each row in the table. Using a switch case structure, the developer can return an object such as { skip: true }, where the skip property indicates whether the row should be skipped based on specific conditions. In the case of an object like { skip: true, value: '<span style="color: red;">Inactive User</span>' }, the value property represents the HTML content that should be displayed in that row.

Example: 

this.__ui.on('columnDataBind', function (args) {
    switch (args.record.isActive) {
        case false:
            return {
                skip: true
        };
            break;
    }
});

 

  • render()

    It provides developers with the ability to customize the display logic of the view, tailoring its content and behavior to meet specific needs.

  • buildDataSourceArgs()

    Allows the developer to design or customize the arguments or parameters of the data source bound to the view.

 

NB🚨: The developer must ensure that the appropriate information is provided based on the type of data source bound to the view:

  • Use resolve({ parameters: [] }); if a storedQuery is bound to the view.
  • Use resolve({ arguments: [] }); if a storedFunction is bound to the view.

 

EVENTSDESCRIPTION
onBeforeRowDataBind()Triggered before the data-binding process for a row. Allows customization or modification of data before it is displayed in the row.
onAfterRowDataBind()Triggered after the data has been bound to a row. Enables applying specific styles or behaviors to the row once the data is displayed.
onBeforeColumnDataBind()Triggered before the data-binding process for a column. Ideal for manipulating or customizing data before it is displayed in a cell.
onAfterColumnDataBind()Triggered after the data has been bound to a column. Allows adjustments to the display or final modifications to the cell.

 

How To Instanciate A List View

To instantiate a list view, the following method is used:

$activator.ui.renderListView({
        container: "", // The JQuery DOM container
        name: "", // The List View name
        model: {
        // Add the necessary data for the List View here
        // If your List View does not expect any param, just send an empty object {}
    }
}).then((listView) => {
    //Stuffs to do after the listView is rendered
});

 

 ✋IMPORTANT: List View Initialization can be done anywhere in component of type Driver (Helper, Content Provider, Driver, Menu Item Driver, Tabbar Driver, etc…).

 

Conclusion

In conclusion, the List View component in Activator provides a powerful and flexible solution for displaying and managing data in an interactive table. Through its various sub-components, such as the List View Driver, View, and View Driver, it enables advanced customization, efficient event handling, and precise configuration of columns and actions. This component ensures an optimized user experience while reducing development complexity. After exploring the numerous possibilities offered by the List View, it is only natural to turn to the Form component, which complements this dynamic by simplifying data entry and management.