DATA_TABLE_COLUMN

columns object for datatables.net

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greasyfork.org/scripts/391970/746961/DATA_TABLE_COLUMN.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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?version=746956
// @require      https://greasyfork.org/scripts/391608-privateproperty/code/PrivateProperty.js?version=744693
// @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);
        }
    };
})();