Browse Source

Up docs API

add-css-mount-events
Artur Arseniev 8 months ago
parent
commit
4f49163a01
  1. 64
      docs/api/datasources.md

64
docs/api/datasources.md

@ -3,40 +3,62 @@
## DataSources ## DataSources
This module manages data sources within the editor. This module manages data sources within the editor.
You can initialize the module with the editor by passing an instance of `EditorModel`. Once the editor is instantiated, you can use the following API to manage data sources:
```js ```js
const editor = new EditorModel(); const editor = grapesjs.init({ ... });
const dsm = new DataSourceManager(editor); const dsm = editor.DataSources;
``` ```
Once the editor is instantiated, you can use the following API to manage data sources: ## Available Events
* `data:add` Added new data source.
```js ```javascript
const dsm = editor.DataSources; editor.on('data:add', (dataSource) => { ... });
``` ```
* [add][1] - Add a new data source. * `data:remove` Data source removed.
* [get][2] - Retrieve a data source by its ID.
* [getAll][3] - Retrieve all data sources.
* [remove][4] - Remove a data source by its ID.
* [clear][5] - Remove all data sources.
Example of adding a data source: ```javascript
editor.on('data:remove', (dataSource) => { ... });
```
```js * `data:update` Data source updated.
const ds = dsm.add({
id: 'my_data_source_id', ```javascript
records: [ editor.on('data:update', (dataSource, changes) => { ... });
{ id: 'id1', name: 'value1' }, ```
{ id: 'id2', name: 'value2' }
] * `data:path` Data record path update.
```javascript
editor.on('data:path:SOURCE_ID.RECORD_ID.PROP_NAME', ({ dataSource, dataRecord, path }) => { ... });
editor.on('data:path', ({ dataSource, dataRecord, path }) => {
console.log('Path update in any data source')
}); });
``` ```
### Parameters * `data:pathSource` Data record path update per source.
```javascript
editor.on('data:pathSource:SOURCE_ID', ({ dataSource, dataRecord, path }) => { ... });
```
* `data` Catch-all event for all the events mentioned above.
```javascript
editor.on('data', ({ event, model, ... }) => { ... });
```
## Methods
* [add][1] - Add a new data source.
* [get][2] - Retrieve a data source by its ID.
* [getAll][3] - Retrieve all data sources.
* [remove][4] - Remove a data source by its ID.
* [clear][5] - Remove all data sources.
* `em` **EditorModel** Editor model. [DataSource]: datasource.html
## add ## add

Loading…
Cancel
Save