DATA_TABLE_COLUMN

columns object for datatables.net

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/391970/746961/DATA_TABLE_COLUMN.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
        }
    };
})();