getState

returns the reactive state object of Pivot

object getState();
objectstate object

Example

// returns the current state 
const state = $$("pivot").getState();
 
// switches the widget to the "chart" mode 
state.mode = "chart";

Related samples

Details

The returned state object contains the following properties and methods:

{
  chart: {
    scale: "linear",
    type: "bar"
  },
  config: true,
  datatable: {
    footer: true,
    maxY: true
  },
  fields: [
    {name: "oil", value: "oil", type: "number"},
    // other fields
  ],
  mode: "tree",
  readonly: false,
  structure: { ...structure config }
}

Properties

  • chart - defines settings for the chart in the chart mode. Inside this object you can provide any setting valid for the Chart widget. It also has the following settings of its own:
  • config (boolean) - shows whether the configuration form is opened
  • datatable - defines settings for the grid in the table and tree modes. Inside this object you can provide any setting valid for the Datatable widget. It also has the following settings of its own:
    • footer (boolean, string) - defines whether to show a sum of values in the column footer. Possible values are:
      • true
      • false (by default)
      • "sumOnly" - to calculate totals only for "sum" columns.
    • minX (boolean) - highlights the lowest value in a row
    • maxX (boolean) - highlights the highest value in a row
    • minY (boolean) - highlights the lowest value in a column
    • maxY (boolean) - highlights the highest value in a column
    • cleanRows (boolean) - defines whether to remove repetitions of values in the first columns (in the table mode).
  • fields (array) - an array with field objects. Each object contains the following fields:
    • name (string) - field name
    • value (string) - field value
    • type (number) - field type. Possible values are:
      • "text" - if field value is a string
      • "number" - if field value is a number
      • "date" - if field value is a date.
    • predicate (string) - predicate of the field
    • prepare (function) - prepares raw data. Accepts a single parameter - raw value (e.g. "2007").
  • mode (string) - defines current display mode. The possible values are:
    • "tree" - treetable is displayed initially (by default)
    • "table" - table is displayed initially
    • "chart" - chart is displayed initially.
  • readonly (boolean) - if true, user cannot configure Pivot via form. false by default.
  • structure - defines the current data structure. Contains the following settings:
    • rows (array) - an array of the rows. The rows are displayed in the treetable
    • columns (array) - an array of the columns. The columns are displayed above the datatable area. Equivalent to the groupBy property in the "chart" mode
    • values (array) - an array of value object settings. Each object includes the following fields:
      • name (string) - field name
      • operation (string, array) - operation name. Built-in (e.g. "sum") or custom one. Can be a single name or an array of names
      • format (function) - a formatting function for the value in the related column
      • color (string) - HEX color for chart series.
    • filters (array) - an array of fields that are used as filters.
    • groupBy (string) - name of the field to group values by. Used in the chart mode. Equivalent to the columns field in the "table" and "tree" modes.

Methods

  • $observe (function) - a handler to listen to changes in the current state of Pivot. It takes 2 parameters:
    • prop (string) - a reactive property to listen changes of
    • handler (function) - a function to execute when changes are made. It takes the only argument:
      • value (any) - the current value of the reactive property. The type of the value (string, array, etc) depends on a reactive property being observed.
  • batch (function)- allows to set several properties at once. Takes the only parameter:
    • props (object) - an object containing the pairs of the property name and the value to set.
See also
Back to top