DATA_TABLE_COLUMN

columns object for datatables.net

Ekde 2019/11/04. Vidu La ĝisdata versio.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/391970/746642/DATA_TABLE_COLUMN.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         DATA_TABLE_COLUMN
// @namespace    hoehleg.userscripts.private
// @version      0.1
// @description  columns object for datatables.net
// @author       Gerrit Höhle
// @require      https://greasyfork.org/scripts/391854-enum/code/Enum.js
// @require      https://greasyfork.org/scripts/391608-privateproperty/code/PrivateProperty.js
// @grant        none
// ==/UserScript==

/* jshint esnext: true */
/* globals Enum, PrivateProperty */
const DATA_TABLE_COLUMN = (() => {
    
    const _renderFunctions = new PrivateProperty();

    return class DATA_TABLE_COLUMN extends Enum {
   
        constructor(...args) {
            super(...args);

            _renderFunctions.set(this, {});

            Object.defineProperties(this, {
                title: {
                    value: this.text, enumerable: true
                },
                data: {
                    get() {
                        return this._data || null;
                    },
                    set(value) {
                        this._data = value;
                    },
                    enumerable: true
                },
                render: {
                    value: (data, type, row, meta) => {
                        const fnc = _renderFunctions.get(this)[type];
                        return  fnc ? fnc(data, row, meta) : data;
                    },
                    enumerable: true
                }
            });
        }

        set renderFunctions({ any, filter = any, display = any, type = any, sort = any }) { 
            _renderFunctions.set(this, Object.fromEntries(Object.entries({ filter, display, type, sort }).filter(([, v]) => typeof v === "function")));
        }

        get renderFunctions() {        
            return _renderFunctions.get(this);
        }
    };
})();