Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 165 additions & 82 deletions docs/guides/configuration.md

Large diffs are not rendered by default.

88 changes: 70 additions & 18 deletions docs/guides/exporting-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,88 @@ title: Exporting data
description: You can explore how to export data in the documentation of the DHTMLX JavaScript Pivot library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Pivot.
---

# Exporting data
# Export data

To export the table data to the XLSX or CSV format, it's necessary to get access to the underlying Table widget instance inside Pivot and apply its API to export data. To do this, you should use the [`getTable`](/api/methods/gettable-method) method and execute the [`export`](/api/table/export) event.
To export Pivot data to XLSX or CSV, access the underlying Table widget instance with the [`getTable()`](/api/methods/gettable-method) method and call `exec("export", ...)` with the required options.

In the example below we get access to the Table instance and trigger the `export`action using the [`api.exec()`](/api/internal/exec-method) method.
The following code snippet accesses the Table instance with `getTable()` and triggers the `export` action for both CSV and XLSX formats:

~~~jsx
const widget = new pivot.Pivot("#root", { /*setting*/});
const widget = new pivot.Pivot("#root", { /* config */ });

// export to CSV
widget.api.getTable().exec("export", {
options: {
format: "csv",
cols: ";"
}
options: {
format: "csv",
cols: ";"
}
});

// export to XLSX
widget.api.getTable().exec("export", {
options: {
format: "xlsx",
fileName: "My Report",
sheetName: "Quarter 1",
}
options: {
format: "xlsx",
fileName: "My Report",
sheetName: "Quarter 1",
}
});
~~~

## Example
## Export to CSV

Use the [`getTable()`](/api/methods/gettable-method) method to access the Table widget instance and call `exec("export", ...)` with `format: "csv"`.

The following code snippet exports the table to CSV with a semicolon as column delimiter:

~~~jsx
widget.api.getTable().exec("export", {
options: {
format: "csv",
fileName: "report",
cols: ";", // column delimiter, "\t" by default
rows: "\n" // row delimiter, "\n" by default
}
});
~~~

## Export to XLSX

The following code snippet exports the table to XLSX with a custom file and sheet name:

~~~jsx
widget.api.getTable().exec("export", {
options: {
format: "xlsx",
fileName: "My Report",
sheetName: "Quarter 1",
header: true, // include header, true by default
footer: true, // include footer, true by default
download: true // trigger file download, true by default
}
});
~~~

Set `download` to `false` to suppress the file download and access the exported data as a Blob via `ev.result` instead.

## Customize export output

Use the following XLSX-specific options to control cell values and styling during export:

- `cellTemplate` — a function to override the exported value of each data cell; receives `value`, `row`, and `column` and returns the custom value
- `headerCellTemplate` — a function to override the exported value of header or footer cells; receives `text`, header cell object, `column`, and `type` (`"header"` or `"footer"`)
- `cellStyle` — a function that returns alignment and format for a data cell
- `headerCellStyle` — a function that returns alignment and format for a header or footer cell
- `styles` — set to `false` to export without styling, or pass an object with style settings for `header`, `cell`, `footer`, `lastHeaderCell`, and `firstFooterCell` cells

:::note
By default, date and number fields export as raw values with the format defined via the [`fields`](/api/config/fields-property) property. If a template is set via [`tableShape`](/api/config/tableshape-property), the rendered value is exported instead. If both `cellTemplate` and `format` are set, `cellTemplate` takes precedence.
:::

In this snippet you can see how to export data:
The live example below demonstrates both export formats:

<iframe src="https://snippet.dhtmlx.com/zjuloqxd?mode=result" frameborder="0" class="snippet_iframe" width="100%" height="600"></iframe>
<iframe src="https://snippet.dhtmlx.com/zjuloqxd?mode=result" frameborder="0" class="snippet_iframe" width="100%" height="600"></iframe>

**Related articles**:
**Related articles**:

- [Date formatting](/guides/localization#date-formatting)
- [`export`](/api/table/export)
- [`export`](/api/table/export)
40 changes: 19 additions & 21 deletions docs/guides/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,47 @@ title: Initialization
description: You can learn about the initialization in the documentation of the DHTMLX JavaScript Pivot library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Pivot.
---

# Initialization
# Initialize Pivot

This guide will give you detailed instructions on how to create Pivot on a page to enrich your application with features of the Pivot table. Take the following steps to get a ready-to-use component:
This guide explains how to add Pivot to a page. Take the following steps to get a ready-to-use component:

1. [Include the Pivot source files on a page](#including-source-files).
2. [Create a container for Pivot](#creating-container).
3. [Initialize Pivot with a constructor](#initializing-pivot).
1. [Include the Pivot source files on a page](#include-source-files).
2. [Create a container for Pivot](#create-a-container).
3. [Initialize Pivot with a constructor](#create-a-pivot-instance).

## Including source files
## Include source files

See also how to download packages: [Downloading packages](/how-to-start#step-1-downloading-and-installing-packages).
Include two files from the `dist/` folder in your HTML page. For information on downloading the package, see [Downloading packages](/how-to-start#step-1-downloading-and-installing-packages).

To create a Pivot app, you need to include 2 source files on your page:
Include the following source files:

- *pivot.js*
- *pivot.css*
- `pivot.js`
- `pivot.css`

Make sure that you set correct relative paths to the source files:
Set correct relative paths to the source files:

~~~html title="index.html"
<script type="text/javascript" src="./dist/pivot.js"></script>
<link rel="stylesheet" href="./dist/pivot.css">
~~~

## Creating container
## Create a container

Add a container for Pivot and give it an ID, for example *"root"*:
Add a container for Pivot and give the container an ID, for example `"root"`:

~~~html title="index.html"
<div id="root"></div>
~~~

## Initializing Pivot
## Create a Pivot instance

Initialize Pivot with the **pivot.Pivot** constructor. It takes two parameters:
Initialize Pivot with the `pivot.Pivot` constructor. It takes two parameters:

- an HTML container (the ID of the HTML container)
- an object with configuration properties

The following code snippet initializes Pivot with fields, data, and a basic config:

~~~jsx
// create Pivot
const table = new pivot.Pivot("#root", {
Expand All @@ -62,14 +64,10 @@ const table = new pivot.Pivot("#root", {
});
~~~

## Configuration properties

:::info
The full list of properties to configure **Pivot** can be found [**here**](api/overview/properties-overview.md).
Find the full list of Pivot configuration properties in the [Properties overview](api/overview/properties-overview.md).
:::

## Example

In this snippet you can see how to initialize **Pivot** with the initial data:
The live example below shows Pivot initialized with sample data:

<iframe src="https://snippet.dhtmlx.com/y2buoahe?mode=result" frameborder="0" class="snippet_iframe" width="100%" height="600"></iframe>
78 changes: 39 additions & 39 deletions docs/guides/integration-with-angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,79 @@ description: You can learn about the integration with Angular in the documentati
# Integration with Angular

:::tip
You should be familiar with basic concepts and patterns of **Angular** before reading this documentation. To refresh your knowledge, please refer to the [**Angular documentation**](https://v17.angular.io/docs).
Familiarize yourself with the basic concepts and patterns of [Angular](https://v17.angular.io/docs) before reading this documentation. See the [Angular documentation](https://v17.angular.io/docs) for reference.
:::

DHTMLX Pivot is compatible with **Angular**. We have prepared code examples on how to use DHTMLX Pivot with **Angular**. For more information, refer to the corresponding [**Example on GitHub**](https://github.com/DHTMLX/angular-pivot-demo).
DHTMLX Pivot is compatible with Angular. For a complete working example, see the [Example on GitHub](https://github.com/DHTMLX/angular-pivot-demo).

## Creating a project
## Create a project

:::info
Before you start to create a new project, install [**Angular CLI**](https://v1.angular.io/cli) and [**Node.js**](https://nodejs.org/en/).
Before creating a new project, install [Angular CLI](https://v17.angular.io/cli) and [Node.js](https://nodejs.org/en/).
:::

Create a new **my-angular-pivot-app** project using Angular CLI. Run the following command for this purpose:
Create a new *my-angular-pivot-app* project using Angular CLI:

~~~json
ng new my-angular-pivot-app
~~~

:::note
If you want to follow this guide, disable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering) when creating new Angular app!
Disable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering) when creating the Angular app to follow this guide.
:::

The command above installs all the necessary tools, so you don't need to run any additional commands.
The command installs all necessary tools. No additional commands are needed.

### Installation of dependencies
### Install dependencies

Go to the new created app directory:
Go to the new project directory:

~~~json
cd my-angular-pivot-app
~~~

Install dependencies and start the dev server. For this, use the [**yarn**](https://yarnpkg.com/) package manager:
Install dependencies and start the dev server using [yarn](https://yarnpkg.com/):

~~~jsx
yarn
yarn start // or yarn dev
~~~

The app should run on a localhost (for instance `http://localhost:3000`).
The app runs on a localhost (for instance `http://localhost:3000`).

## Creating Pivot
## Create a Pivot component

Now you should get the DHTMLX Pivot source code. First of all, stop the app and proceed with installing the Pivot package.
Stop the app and install the Pivot package.

### Step 1. Package installation

Download the [**trial Pivot package**](/how-to-start/#installing-trial-pivot-via-npm-or-yarn) and follow steps mentioned in the README file. Note that trial Pivot is available 30 days only.

### Step 2. Component creation
Download the [trial Pivot package](/how-to-start/#installing-trial-pivot-via-npm-or-yarn) and follow the steps in the README file. The trial version is available for 30 days.

Now you need to create an Angular component, to add Pivot into the application. Create the **pivot** folder in the ***src/app/*** directory, add a new file into it and name it ***pivot.component.ts***. Then complete the steps described below.
### Step 2. Create the component

Create a *pivot* folder in the *src/app/* directory, add a new file named *pivot.component.ts*, then complete the steps below.

#### Import source files

Open the file and import Pivot source files. Note that:
Open *pivot.component.ts* and import Pivot source files.

- if you use PRO version and install the Pivot package from a local folder, the imported path looks like this:
- PRO version installed from a local folder:

~~~jsx
import { Pivot } from 'dhx-pivot-package';
~~~

- if you use the trial version of Pivot, specify the following path:
- Trial version:

~~~jsx
import { Pivot } from '@dhx/trial-pivot';
~~~

In this tutorial you can see how to configure the **trial** version of Pivot.
This tutorial uses the trial version of Pivot.

#### Set the container and initialize Pivot
#### Set up the container

To display Pivot on the page, you need to set the container to render the component inside and initialize Pivot using the corresponding constructor:
Set the container to render the component and initialize Pivot with the constructor:

~~~jsx {1,8,12-13,18-19} title="pivot.component.ts"
import { Pivot } from '@dhx/trial-pivot';
Expand Down Expand Up @@ -109,9 +109,9 @@ export class PivotComponent implements OnInit, OnDestroy {
}
~~~

#### Adding styles
#### Add styles

To display Pivot correctly, you need to provide the corresponding styles. For this purpose, you can create the ***pivot.component.css*** file in the ***src/app/pivot/*** directory and specify important styles for Pivot and its container:
Create the *pivot.component.css* file in the *src/app/pivot/* directory and specify styles for Pivot and its container:

~~~css title="pivot.component.css"
/* import Pivot styles */
Expand All @@ -132,9 +132,9 @@ body {
}
~~~

#### Loading data
#### Load data

To add data into Pivot, you need to provide a data set. You can create the ***data.ts*** file in the ***src/app/pivot/*** directory and add some data into it:
Create the *data.ts* file in the *src/app/pivot/* directory and add your data:

~~~jsx title="data.ts"
export function getData() {
Expand Down Expand Up @@ -172,7 +172,7 @@ export function getData() {
"state": "Colorado",
"expenses": 45,
"type": "Decaf"
}, // othe data items
}, // other data items
];

const fields: any = [
Expand All @@ -192,7 +192,7 @@ export function getData() {
};
~~~

Then open the ***pivot.component.ts*** file. Import the file with data and specify the corresponding data properties to the configuration object of Pivot within the `ngOnInit()` method, as shown below.
Open *pivot.component.ts*, import the data, and pass the data to the Pivot configuration inside `ngOnInit()`:

~~~jsx {2,18,20-21} title="pivot.component.ts"
import { Pivot } from '@dhx/trial-pivot';
Expand Down Expand Up @@ -236,13 +236,13 @@ export class PivotComponent implements OnInit, OnDestroy {
}
~~~

Now the Pivot component is ready to use. When the element will be added to the page, it will initialize the Pivot with data. You can provide necessary configuration settings as well. Visit our [Pivot API docs](/api/overview/properties-overview/) to check the full list of available properties.
The Pivot component is ready. When the element mounts, the component initializes Pivot with data. See the [Pivot API reference](/api/overview/properties-overview/) for the full list of properties.

#### Handling events
#### Handle events

When a user makes some action in the Pivot, it invokes an event. You can use these events to detect the action and run the desired code for it. See the [full list of events](/api/overview/events-overview/).
Pivot fires events when a user interacts with the widget. Use these events to detect actions and run the corresponding code. See the [full list of events](/api/overview/events-overview/).

Open the ***pivot.component.ts*** file and complete the `ngOnInit()` method as in:
Open *pivot.component.ts* and add an event listener inside `ngOnInit()`:

~~~jsx {18-20} title="pivot.component.ts"
// ...
Expand Down Expand Up @@ -272,9 +272,9 @@ ngOnDestroy(): void {
}
~~~

### Step 3. Adding Pivot into the app
### Step 3. Add Pivot to the app

To add the ***PivotComponent*** into the app, open the ***src/app/app.component.ts*** file and replace the default code with the following one:
Open *src/app/app.component.ts* and replace the default code with the following:

~~~jsx {5} title="app.component.ts"
import { Component } from "@angular/core";
Expand All @@ -288,7 +288,7 @@ export class AppComponent {
}
~~~

Then create the ***app.module.ts*** file in the ***src/app/*** directory and specify the *PivotComponent* as shown below:
Create the *app.module.ts* file in the *src/app/* directory and specify `PivotComponent`:

~~~jsx {4-5,8} title="app.module.ts"
import { NgModule } from "@angular/core";
Expand All @@ -305,7 +305,7 @@ import { PivotComponent } from "./pivot/pivot.component";
export class AppModule {}
~~~

The last step is to open the ***src/main.ts*** file and replace the existing code with the following one:
Open *src/main.ts* and replace the existing code with the following:

~~~jsx title="main.ts"
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
Expand All @@ -315,8 +315,8 @@ platformBrowserDynamic()
.catch((err) => console.error(err));
~~~

After that, you can start the app to see Pivot loaded with data on a page.
After that, start the app to see Pivot loaded with data on the page.

![Pivot initialization](../assets/trial_pivot.png)

Now you know how to integrate DHTMLX Pivot with Angular. You can customize the code according to your specific requirements. The final example you can find on [**GitHub**](https://github.com/DHTMLX/angular-pivot-demo).
Customize the code to fit your requirements. See the complete example on [GitHub](https://github.com/DHTMLX/angular-pivot-demo).
Loading