DATA_TABLE_COLUMN

columns object for datatables.net

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greasyfork.org/scripts/391970/746961/DATA_TABLE_COLUMN.js

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

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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