/*
	Author: Paulo Arcegono
	Filename: table.js
	Description: This is to initialize the dataTable and load the data in teh datatable
	Dependencies:
	- datatable.js
	- jquery
	
		How to use:
		1. Check the table component html
		2. Add specific ID for the datable then add class "dt-responsive" to the table element
		3. Initialize the datatable using  (ID).dataTable();
For more info:
https://datatables.net/

*/

;(function($) {
    'use strict'
    B2C.datatable = {
        init: function(dataTable) {
            this._default = {
                target: '.js-datatable'
            }

            this._dataTable = $.extend({}, this._default, dataTable)

            if (!$(this._dataTable.target).length) return
            this.domCache()
            this.evenListener()
        },
        domCache: function() {
            this.$jsDataTable = $(this._dataTable.target)
        },
        evenListener: function() {
            //  const self = B2C.datatable

            //this.$jsDataTable.load(self.loadDataTable);
            this.$jsDataTable.DataTable({
                // pagination option
                pagingType: 'full_numbers',
                language: {
                    paginate: {
                        first: '<',
                        last: '>'
                    }
                },
                //set Filter label
                lengthMenu: [[25, 50, 100, -1], [25, 50, 100, 'All']],
                //Set true to make the table responsive
                responsive: true,
                rowReorder: {
                    selector: 'td:nth-child(2)'
                },
                //remove search filter
                searching: false
            })
        }
    }
    B2C.datatable.init()
})(jQuery)
