The DataSource
class represents a data source within the editor.
It manages a collection of data records and provides methods to interact with them.
The DataSource
can be extended with transformers to modify records during add, read, and delete operations.
const dataSource = new DataSource({
records: [
{ id: 'id1', name: 'value1' },
{ id: 'id2', name: 'value2' }
],
}, { em: editor });
dataSource.addRecord({ id: 'id3', name: 'value3' });
props
DataSourceProps Properties to initialize the data source.opts
DataSourceOptions Options to initialize the data source.
Returns the default properties for the data source. These include an empty array of records and an empty object of transformers.
Returns Object The default attributes for the data source.
Initializes a new instance of the DataSource
class.
It sets up the transformers and initializes the collection of records.
If the records
property is not an instance of DataRecords
, it will be converted into one.
props
DataSourceProps<DRProps> Properties to initialize the data source.opts
DataSourceOptions Options to initialize the data source.
Retrieves the collection of records associated with this data source.
Returns DataRecords<DRProps> The collection of data records.
Retrieves the editor model associated with this data source.
Returns EditorModel The editor model.
Adds a new record to the data source.
record
DRProps The properties of the record to add.opts
AddOptions? Options to apply when adding the record.
Returns DataRecord The added data record.
Retrieves a record from the data source by its ID.
Returns (DataRecord<DRProps> | undefined) The data record, or undefined
if no record is found with the given ID.
Retrieves all records from the data source.
Each record is processed with the getRecord
method to apply any read transformers.
Returns Array<(DataRecord<DRProps> | undefined)> An array of data records.
Removes a record from the data source by its ID.
id
(string | number) The ID of the record to remove.opts
RemoveOptions? Options to apply when removing the record.
Returns (DataRecord<DRProps> | undefined) The removed data record, or undefined
if no record is found with the given ID.
Replaces the existing records in the data source with a new set of records.
records
Array<DRProps> An array of data record properties to set.
Returns Array<DataRecord> An array of the added data records.