View on GitHub

vue-jd-table

An advanced and flexible Vue.js 2.x component for displaying data tables.

JD-Table / Events

This section explains how communication works between your app and the JD-Table component. There are two types of events:

Why not use an event bus?

An event bus is another Vue instance that is used between parent and child components to emit events. They are my personal favorite way method of communication and the community recommended goto choice.

So why didn’t I use one? The simple answer is that I didn’t want to create a component that required the user to create an event bus to use and install JD-Table. It adds setup complexity and overhead users may not want in their apps.

Your App to JD-Table Events

These are events triggered from your application (parent) to JD-Table (child). JD-Table accepts the following events:

How to trigger App to JD-Table event

Recall from the README the following template setup …

<template>
    <div id="bisNamedAccount">
        <JDTable
        :option                 = "tableOptions"
        :loader                 = "tableLoader"
        :event-from-app         = "eventFromApp"
        :event-from-app-trigger = "eventFromAppTrigger"
        @event-from-jd-table    = "processEventFromApp( $event )"
    />
    
        <iframe id="excelExportArea" style="display:none"></iframe>
    </div>
</template>

In the above setup, you would configure the details of the event using a property called eventFromApp and trigger the event using another property called eventFromAppTrigger.

The eventFromApp is a object that contains the event name and payload:

this.eventFromApp =
{
    name    : 'tableError',
    payload : 'Error: Request for data from the server failed (500). Details: Access Denied'
}

Now that you’ve configured an event you need to trigger it in the JD-Table:

// Trigger the event.
this.eventFromAppTrigger = true;

// Reset the trigger event.
this.$nextTick( () =>
{
    this.eventFromAppTrigger = false;
});

Setting the variable eventFromAppTrigger to true triggers the event. However, you must ensure to reset the trigger variable to false. This must be done on the nextTick (VueJS function). If you do not reset the variable on nextTick the vent will not run.

Typically it is better to configure the trigger as a method in Vue. In this way you only need to call your method.

// Triggers the currently queued JD-Table event to run.
triggerEvent : function ()
{
    // Trigger the event.
    this.eventFromAppTrigger = true;

    // Reset the trigger event.
    this.$nextTick( () =>
    {
        this.eventFromAppTrigger = false;
    });
},

JD-Table Events to Your App

These are events triggered from the JD-Table component using the VueJS $emit function. These can be captured and sent to a method in your app by registering the event in your template.

The primary purpose for these events is to indicate an action that happens within JD-Table that requires external (parent) intervention. For example, if a ‘Refresh’ event is triggered, the user has clicked the “Refresh” data button. As such, this should trigger a update in the dataset - which nearly everytime will be a REST API call from the parent (followed by a sendData event).

Another purpose is to take note of the JD-Table’s component state. You can create a snapshot of this data to be used when a user migrates away from the table then uses “Back” in there browser. If this happens you can inject the old state to show them the table as they left it. You can also create user specific saved states.

Capture the Event
@event-from-jd-table = "processEventFromApp( $event )"

Full Example:

<div id="bisNamedAccount">
    <JDTable
    :option                 = "tableOptions"
    :loader                 = "tableLoader"
    :event-from-app         = "eventFromApp"
    :event-from-app-trigger = "eventFromAppTrigger"
    @event-from-jd-table    = "processEventFromApp( $event )"
/>

With the exception of the “Refresh” and “AddNew” event, all other events are intended for external data processing (dataProvider = 1 option).

In the example above, whenever JD-Table emit’s an event it will trigger the processEventFromApp() method with the event details in $event.

Component State (From JD-Table)

When a event is triggered from JD-Table it is emitted with the current JD-Table component state. This provides you with a bunch of details as to what the current state is of the table and its features.

The component state is a object and contains the following details:

componentState =
{
    // Boolean indicating if a search text has been applied to the table.
    searchApplied,
    // String hold the current applied search text.
    searchText,
    // Array of currently applied filters to the table.
    filterApplied,
    // Number indicating the currently selected max rows that can be displayed on a page when pagination is enabled.
    pageLimit,
    // Number indicating the current page the user is on when pagination is enabled.
    currentPage,
    // String indicating the last action performed (this is the name of the event).
    lastAction,
    // String indicating the column that is currently selected as the sort column.
    sortColumn,
    // String indicating the direction of the sorted column: 'asc' or 'desc'.
    sortDirection
    // String indicating the special sort instructions for the column.
    sortSpecial
    // Object of the row data currently selected.
    selectedItem
    // Number indicating the selected row index value of the data.
    selectedIndex
    // Name of the current selected view.
    currentView
}

Managing Events

As all events are sent to a single callback function you must manage the

JD-Table Events

REMINDER: When performing any event, be sure to remember to modify your API calls for data based on the componentState values like search, filter and pagination.

AddItem

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'AddItem' )
            {
            	// Using Vue Router
                router.push('addTableItem');
            }
        }
    }
    
    // ...
}

AddItemNewWindow

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'AddItemNewWindow' )
            {
            	// Using Vue Router
                router.push('addTableItem');
            }
        }
    }
    
    // ...
}

ViewItem

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'ViewItem' )
            {
            	// Using Vue Router
                router.push('addTableItem');
            }
        }
    }
    
    // ...
}

ViewItemNewWindow

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'ViewItemNewWindow' )
            {
            	// Using Vue Router
                router.push('addTableItem');
            }
        }
    }
    
    // ...
}

EditItem

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'AddNew' )
            {
            	// Using Vue Router
                router.push('addTableItem');
            }
        }
    }
    
    // ...
}

EditItemNewWindow

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'EditItemNewWindow' )
            {
            	// Using Vue Router
                router.push('addTableItem');
            }
        }
    }
    
    // ...
}

DeleteItem

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'DeleteItem' )
            {
            	// Using Vue Router
                router.push('addTableItem');
            }
        }
    }
    
    // ...
}

Refresh

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                this.getDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'sendData',
                        payload : JSON.parse( result )
                    };

                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

See How to trigger App to JD-Table event to understand the method for trigging events (this.triggerEvent).

ExcelExport

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                this.getExportDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'exportExcel',
                        payload : JSON.parse( result )
                    };

                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

PaginationGoToSpecificPage

NOTE: All pagination event examples are the same. While one even would suffice for all pagination actions, individual events were kept for the sake of a giving developers more granular control over parent/app actions.

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
            	// Use this in your API call.
            	this.currentSkipIndex = ( componentState.currentPage - 1 ) * componentState.pageLimit;

                this.getDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'sendData',
                        payload :
                        {
                            data          : JSON.parse( result ),
                            count         : this.currentQueryClauseCount,
                            firstRowIndex : this.currentSkipIndex
                        }
                    }
    
                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

TIP: When using dataProvider = 1 (external), you need to provide a total count of how many rows of data exist in the current query (this is for pagination). Try storing the total count (length) in your app as a data variable so you can refer to it like above (this.currentQueryClauseCount).

PaginationGoToNextPage

NOTE: All pagination event examples are the same. While one even would suffice for all pagination actions, individual events were kept for the sake of a giving developers more granular control over parent/app actions.

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
            	// Use this in your API call.
            	this.currentSkipIndex = ( componentState.currentPage - 1 ) * componentState.pageLimit;

                this.getDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'sendData',
                        payload :
                        {
                            data          : JSON.parse( result ),
                            count         : this.currentQueryClauseCount,
                            firstRowIndex : this.currentSkipIndex
                        }
                    }
    
                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

TIP: When using dataProvider = 1 (external), you need to provide a total count of how many rows of data exist in the current query (this is for pagination). Try storing the total count (length) in your app as a data variable so you can refer to it like above (this.currentQueryClauseCount).

PaginationGoToLastPage

NOTE: All pagination event examples are the same. While one even would suffice for all pagination actions, individual events were kept for the sake of a giving developers more granular control over parent/app actions.

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
            	// Use this in your API call.
            	this.currentSkipIndex = ( componentState.currentPage - 1 ) * componentState.pageLimit;

                this.getDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'sendData',
                        payload :
                        {
                            data          : JSON.parse( result ),
                            count         : this.currentQueryClauseCount,
                            firstRowIndex : this.currentSkipIndex
                        }
                    }
    
                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

TIP: When using dataProvider = 1 (external), you need to provide a total count of how many rows of data exist in the current query (this is for pagination). Try storing the total count (length) in your app as a data variable so you can refer to it like above (this.currentQueryClauseCount).

PaginationGoToPreviousPage

NOTE: All pagination event examples are the same. While one even would suffice for all pagination actions, individual events were kept for the sake of a giving developers more granular control over parent/app actions.

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
            	// Use this in your API call.
            	this.currentSkipIndex = ( componentState.currentPage - 1 ) * componentState.pageLimit;

                this.getDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'sendData',
                        payload :
                        {
                            data          : JSON.parse( result ),
                            count         : this.currentQueryClauseCount,
                            firstRowIndex : this.currentSkipIndex
                        }
                    }
    
                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

TIP: When using dataProvider = 1 (external), you need to provide a total count of how many rows of data exist in the current query (this is for pagination). Try storing the total count (length) in your app as a data variable so you can refer to it like above (this.currentQueryClauseCount).

PaginationGoToFirstPage

NOTE: All pagination event examples are the same. While one even would suffice for all pagination actions, individual events were kept for the sake of a giving developers more granular control over parent/app actions.

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
            	// Use this in your API call.
            	this.currentSkipIndex = ( componentState.currentPage - 1 ) * componentState.pageLimit;

                this.getDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'sendData',
                        payload :
                        {
                            data          : JSON.parse( result ),
                            count         : this.currentQueryClauseCount,
                            firstRowIndex : this.currentSkipIndex
                        }
                    }
    
                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

TIP: When using dataProvider = 1 (external), you need to provide a total count of how many rows of data exist in the current query (this is for pagination). Try storing the total count (length) in your app as a data variable so you can refer to it like above (this.currentQueryClauseCount).

PaginationPageLimitChange

NOTE: All pagination event examples are the same. While one even would suffice for all pagination actions, individual events were kept for the sake of a giving developers more granular control over parent/app actions.

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
            	// Use this in your API call.
            	this.currentSkipIndex = ( componentState.currentPage - 1 ) * componentState.pageLimit;

                this.getDataFromAPI( ( result ) =>
                {
                    this.eventFromApp =
                    {
                        name    : 'sendData',
                        payload :
                        {
                            data          : JSON.parse( result ),
                            count         : this.currentQueryClauseCount,
                            firstRowIndex : this.currentSkipIndex
                        }
                    }
    
                    this.triggerEvent();
                });
            }
        }
    }
    
    // ...
}

TIP: When using dataProvider = 1 (external), you need to provide a total count of how many rows of data exist in the current query (this is for pagination). Try storing the total count (length) in your app as a data variable so you can refer to it like above (this.currentQueryClauseCount).

ChangeView

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeView' )
            {           	
               this.getDataFromAPI( ( result ) =>
               {
                   this.eventFromApp =
                   {
                       name    : 'sendData',
                       payload : JSON.parse( result )
                   };

                   this.triggerEvent();
               });
            }
        }
    }
    
    // ...
}

ChangeSort

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeView' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeSort' )
            {
            	// Check for sorting and adjust API query accordingly ..
            	
               this.getDataFromAPI( ( result ) =>
               {
                   this.eventFromApp =
                   {
                       name    : 'sendData',
                       payload : JSON.parse( result )
                   };

                   this.triggerEvent();
               });
            }
        }
    }
    
    // ...
}

AddFilter

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeView' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeSort' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'AddFilter' )
            {
            	// Check for filters and adjust API query accordingly.
            	
               this.getDataFromAPI( ( result ) =>
               {
                   this.eventFromApp =
                   {
                       name    : 'sendData',
                       payload : JSON.parse( result )
                   };

                   this.triggerEvent();
               });
            }
        }
    }
    
    // ...
}

RemoveFilter

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeView' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeSort' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'AddFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'RemoveFilter' )
            {
            	// Check for filters and adjust API query accordingly.
            	
               this.getDataFromAPI( ( result ) =>
               {
                   this.eventFromApp =
                   {
                       name    : 'sendData',
                       payload : JSON.parse( result )
                   };

                   this.triggerEvent();
               });
            }
        }
    }
    
    // ...
}

ClearFilter

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeView' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeSort' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'AddFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'RemoveFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ClearFilter' )
            {
            	// Check for component state details and adjust API query accordingly.
            	
               this.getDataFromAPI( ( result ) =>
               {
                   this.eventFromApp =
                   {
                       name    : 'sendData'
                   };

                   this.triggerEvent();
               });
            }
        }
    }
    
    // ...
}

ApplySearch

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeView' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeSort' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'AddFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'RemoveFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ClearFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ApplySearch' )
            {
            	// Modify REST API query for search details.
            	
               this.getDataFromAPI( ( result ) =>
               {
                   this.eventFromApp =
                   {
                       name    : 'sendData',
                       payload : JSON.parse( result )
                   };

                   this.triggerEvent();
               });
            }
        }
    }
    
    // ...
}

ClearSearch

Example
export default
{
    // ...
	
    methods :
    {
        // Triggered when the JD-Table emits a "eventFromJDTable" event.
        processEventFromApp : function ( componentState )
        {
            if ( componentState.lastAction === 'Refresh' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'ExcelExport' )
            {
                // ...
            }
            else if ( componentState.lastAction === 'PaginationGoToSpecificPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToNextPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToLastPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToPreviousPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationGoToFirstPage' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'PaginationPageLimitChange' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeView' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ChangeSort' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'AddFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'RemoveFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ClearFilter' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ApplySearch' )
            {
                // ..
            }
            else if ( componentState.lastAction === 'ClearSearch' )
            {
            	// Modify REST API query to remove search details.
            	
               this.getDataFromAPI( ( result ) =>
               {
                   this.eventFromApp =
                   {
                       name    : 'sendData',
                       payload : JSON.parse( result )
                   };

                   this.triggerEvent();
               });
            }
        }
    }
    
    // ...
}

Component State

Whenever a user performs an event in JD-Table that changes something (ie. search, filter, sort, pagination, etc.) the component will emit an event containing the current state of JD-Table (componentState).

The primary use for this object is to provide information to the parent when dataProvider option is set to 1. This allows the parent to obtain the correct data according to the tables state (search, filter, etc.).

However, another use for componentState is to save it and re-use it to put JD-Table into the saved state. This is perfect for single page applications when the user moves away from the table then clicks “Back”. If you don’t record the component state, then JD-Table will just revert to its defaults when the user goes back to the page. However, if you store the componentState (ie. in Vuex) you an send it along with the sendData event to provide a better user experience.

When setting a new component state the following will be processed:

WARNING: It is not recommended to modify any of the the component state values directly. When JD-Table emits the componentState object, store it as is and do not modify it. When updating the component state, send the same (stored) component state back to JD-Table. Any changes in the structure of this object can cause unknown behaviour.