structure

задает настройки для Pivot (поля, операции, фильтры)

object structure;

Example

webix.ui({
    view:"pivot",
    structure: { 
        "rows": ["form", "name"],
        "columns": ["year"],
        "values": [
            { "name": "gdp", "operation": "sum" },
            { "name": "oil", "operation": "sum" }
        ],
        "filters": [
            {
                "name": "continent",
                "value": {
                    "condition": {
                        "filter": "c",
                        "type": "notContains"
                    },
                    "includes": [
                        "Europe",
                        "Asia"
                    ]
                }
            }
        ]
    }
});

Related samples

Details

Объект содержит следующие поля:

  • rows (array) - массив рядов таблицы
  • columns (array) - массив столбцов таблицы. Эквивалентно полю groupBy в режиме "chart"
  • values (array) - массив с настройками значений. Каждый объект содержит следующие поля:
    • name (string) - название поля
    • operation (string, array) - название операции. Встроенной ("sum", "min", "max", "count", "avg", "wavg", "counta", "countunique", "median", "product", "var", "varp", "stdev", "stdevp", "any") или кастомной. Свойство принимает строку или массив строк
    • format (function) - форматирующая функция
    • color (string) - цвет для секций чартов.
  • filters (array) - массив полей для фильтрации. Description of properties for a single filter entry:
    • name (string) - the name of an existing field
    • value (object) - the value of the filter:
      • condition (object) - includes the condition type and a value to filter by.
        For example: { condition: "contains", value: "a" }
        The list of supported types is in the Filter API. See conditions
      • includes (array | null) - optional, an array of explicitly selected values. Depending on the field type, the array can include string or number values (dates will be converted to timestamps). The absence of this property or null are equal to "select all". The empty array unselects all values (the result of filtering will be empty).
  • groupBy (string) - название поля, по которому происходит группирование. Используется в режиме чарта. Эквивалентно полю columns в режимах "table" и "tree".

Как задать structure динамически

Т.к. это реактивное свойство, вы можете получить доступ к нему, а также изменить его значение динамически через состояние виджета:

$$("pivot").getState().structure = {/* новые настройки */};

Ещё один способ — вызов метода setStructure с объектом настроек в качестве параметра:

$$("structures").attachEvent("onItemClick", function(id) {
    var str = webix.copy(this.getItem(id).structure);
    $$("pivot").setStructure(str);
});

Как получить текущий structure

Вы можете получить текущие настройки через состояние виджета:

$$("pivot").getState().structure;

или же с помощью метода getStructure:

const structure = $$("pivot").getStructure();
/*
    {
        columns: ["year"],
        filters: [
            {
                name: "continent",
                value: {
                    condition: {
                        "filter": "c",
                        "type": "notContains"
                    },
                    includes: [
                        "Europe",
                        "Asia"
                    ]
                }
            }
        ],
        groupBy: "year",
        rows: ["form", 'name"],
        values: [{name: "oil", operation: "min", color: "#e33fc7"}, ...]
    }
*/
See also
Наверх
If you have not checked yet, be sure to visit site of our main product Webix ui widget library and page of javascript pivot grid product.