Skip to content

Commit 51595c6

Browse files
author
Victory
committed
[add] docs for export/import JSON data
1 parent 245fe9c commit 51595c6

File tree

5 files changed

+85
-5
lines changed

5 files changed

+85
-5
lines changed

docs/api/export_json_method.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
sidebar_label: json()
3+
title: json export method
4+
description: You can learn about the json export method in the documentation of the DHTMLX JavaScript Spreadsheet library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Spreadsheet.
5+
---
6+
7+
# json()
8+
9+
### Description
10+
11+
@short: Exports data from a spreadsheet into a JSON file
12+
13+
### Usage
14+
15+
~~~jsx
16+
json(): void;
17+
~~~
18+
19+
### Example
20+
21+
~~~jsx {5}
22+
const spreadsheet = new dhx.Spreadsheet("spreadsheet", {
23+
// config parameters
24+
});
25+
// exports data from a spreadsheet into a JSON file
26+
spreadsheet.export.json();
27+
~~~
28+
29+
**Changelog:** Added in v4.3
30+
31+
**Related articles:** [Data loading and export](loading_data.md)
32+
33+
**Related sample:** [Spreadsheet. Export/import JSON](https://snippet.dhtmlx.com/e3xct53l)

docs/api/overview/actions_overview.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ description: You can have an Actions overview of the DHTMLX JavaScript Spreadshe
66

77
# Actions overview
88

9-
:::info
10-
From v4.3, the Spreadsheet library introduces a new conception of interaction with Spreadsheet events.
11-
:::
9+
This section is dedicated to a new conception of interaction with Spreadsheet events.
1210

13-
Now DHTMLX Spreadsheet includes a pair of the [beforeAction](api/spreadsheet_beforeaction_event.md)/[afterAction](api/spreadsheet_afteraction_event.md) events that are intended to make your code simple and concise. They will fire right before an action is executed and indicate which exactly action has been performed.
11+
Starting from v4.3, DHTMLX Spreadsheet includes a pair of the [beforeAction](api/spreadsheet_beforeaction_event.md)/[afterAction](api/spreadsheet_afteraction_event.md) events that are intended to make your code simple and concise. They will fire right before an action is executed and indicate which exactly action has been performed.
1412

1513
~~~js
1614
spreadsheet.events.on("beforeAction", (actionName, config) => {

docs/api/spreadsheet_load_method.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,35 @@ Please note that the component supports import from Excel files with the **.xlsx
6868

6969
DHTMLX Spreadsheet uses the WebAssembly-based library [Excel2Json](https://github.com/dhtmlx/excel2json) for import of data from Excel. [Check the details](loading_data.md#loading-excel-file-xlsx).
7070

71+
### Loading JSON files
72+
73+
It is possible to allow end users to load a JSON file into the spreadsheet via the File Explorer. To do that:
74+
75+
- Specify a button to open the File Explorer where ".json" files can be selected:
76+
77+
~~~html
78+
<section class="dhx_sample-controls">
79+
<button class="dhx_sample-btn dhx_sample-btn--flat" onclick="json()">Import json</button>
80+
</section>
81+
~~~
82+
83+
84+
- Call the **load()** method with two parameters: an empty string as an URL and the type of data to load ("json"):
85+
86+
~~~js
87+
const spreadsheet = new dhx.Spreadsheet("spreadsheet", {
88+
menu: true,
89+
});
90+
91+
spreadsheet.parse(dataset);
92+
93+
function json() {
94+
spreadsheet.load("", "json"); // loads data from a .json file
95+
}
96+
~~~
97+
98+
Check the [example](https://snippet.dhtmlx.com/e3xct53l).
99+
100+
**Changelog:** The ability to load a JSON file via the File Explorer was added in v4.3
101+
71102
**Related articles:** [Data loading and export](loading_data.md)

docs/loading_data.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ spreadsheet.load("../common/data.json");
125125

126126
**Related sample**: [Spreadsheet. Load Data](https://snippet.dhtmlx.com/ih9zmc3e)
127127

128+
129+
:::info
130+
If you need to provide end users with the ability to import a JSON file into the spreadsheet via the File Explorer, read [Loading JSON files](api/spreadsheet_load_method.md#loading-json-files).
131+
:::
132+
128133
### Loading CSV data
129134

130135
You can also load data in the CSV format. For this, you need to call the [](api/spreadsheet_load_method.md) method and pass the name of the format ("csv") as the second parameter:
@@ -223,6 +228,8 @@ spreadsheet2.parse(state);
223228

224229
## Exporting data
225230

231+
### Export into Excel
232+
226233
DHTMLX Spreadsheet provides the ability to export data from a spreadsheet into an Excel file. There are corresponding controls in the Toolbar and Menu in the user interface:
227234

228235
- Menu: File -> Download as..-> Microsoft Excel(.xlsx)
@@ -233,7 +240,7 @@ DHTMLX Spreadsheet provides the ability to export data from a spreadsheet into a
233240

234241
![Export from Excel toolbar](assets/export_xlsx.png)
235242

236-
### How to export data
243+
#### How to export data
237244

238245
{{note Please note that the export feature won't work in the Internet Explorer browser.}}
239246

@@ -263,3 +270,13 @@ spreadsheet.export.xlsx();
263270
{{note Please note that the component supports export to Excel files with the **.xlsx** extension only.}}
264271

265272
Check the steps of [importing data from an Excel file into Spreadsheet](#loading-excel-file-xlsx).
273+
274+
### Export into JSON
275+
276+
From v4.3, the library also includes the ability to export data from a spreadsheet into a JSON file. Use the [json()](api/export_json_method.md) method of the Export object for this purpose:
277+
278+
~~~js
279+
spreadsheet.export.json();
280+
~~~
281+
282+
**Related sample**: [Spreadsheet. Export/import JSON](https://snippet.dhtmlx.com/e3xct53l)

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ module.exports = {
201201
id: "api/overview/export_overview"
202202
},
203203
items: [
204+
"api/export_json_method",
204205
"api/export_xlsx_method",
205206
],
206207
},

0 commit comments

Comments
 (0)