DataProviderBase
Base classes for LocalDataProvider and LocalTreeDataProvider
Signature:
export declare abstract class DataProviderBase
Remarks
All properties and methods of DataProviderBase can be called only from subclasses that inherit it.
[subclass]
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(undoable) | Constructs a new instance of the DataProviderBase class |
Properties
Property | Type | Description |
---|---|---|
amText | string | String corresponding to AM in data |
baseYear | number | When the year of the data is 2 digits, the year based on |
booleanFormat | string | Format for parsing data into Boolean |
checkStates | boolean | Whether to enable row state management |
commitBeforeDataEdit | boolean | Whether to automatically commit previous edits when calling a change function (setValue() , etc.) for another row while in edit state |
datetimeFormat | string | Format for parsing date data in text format into datetime values |
deletable | boolean | Whether rows can be deleted |
deleteCreated | boolean | Whether to actually delete the added row when deleting it |
insertable | boolean | Whether rows can be inserted |
pmText | string | String corresponding to PM in data |
restoreMode | RestoreMode | restore mode |
softDeleting | boolean | When deleting a row, whether to change the RowState without actually deleting it |
strictRestore | boolean | Whether to recognize undefined , null , and empty strings as different values when restored |
subTypeEnabled | boolean | Whether to enable the subType property of DataField |
undoable | boolean | Whether to use undo/redo |
updatable | boolean | Whether rows can be modified |
valuesCallback | ObjectToValuesCallback | Callback called for each row when data in json format is entered into the dataProvider |
Methods
Method | Type | Description |
---|---|---|
addField(field, resetFields, calculateData) | addField(field: DataFieldInput, resetFields?: boolean, calculateData?: boolean): DataField ; | Create additional fields. |
beginUpdate() | beginUpdate(): void; | Specifies the starting point of batch update. |
checkRowStates(value) | checkRowStates(value: boolean): void; | Specifies whether to record row status. |
clearCommandStack() | clearCommandStack(): void; | Initialize the Command Stack. |
clearRowStates(deleteRows, rowEvents) | clearRowStates(deleteRows: boolean, rowEvents?: boolean): void; | Removes the state of all rows. |
clearSavePoints() | clearSavePoints(): void; | Remove all recovery points. |
destroy() | destroy(): any; | Releases the DataProvider object from memory. |
endUpdate(refresh) | endUpdate(refresh?: boolean): void; | Specifies the completion point of batch update. |
exportToCsv(options) | exportToCsv(options: DataExportOptions): void; | Export the data set as a CSV file. |
fieldByName(name) | fieldByName(name: string): DataField; | Returns the field corresponding to the name. |
getAllStateRows() | getAllStateRows(): RowStateList; | Returns the index of all rows with a status value. |
getDataRowId(dataRow) | getDataRowId(dataRow: number): number; | Gets the dataRowId managed internally. |
getDistinctValues(field, maxCount, sortDir) | getDistinctValues(field: string | number, maxCount?: number, sortDir?: SortDirection): any[]; | Returns non-duplicate values of the field. |
getFieldCount() | getFieldCount(): number; | Returns the number of currently configured fieldsets. |
getFieldIndex(fieldName) | getFieldIndex(fieldName: string): number; | Returns the index corresponding to the field name. |
getFieldName(fieldIndex) | getFieldName(fieldIndex: number): string; | Returns the name of the field at a specific index. |
getFieldNames() | getFieldNames(): string[]; | Returns the names of fields. |
getFields() | getFields(): DataField[]; | DataField Returns objects. |
getOptions() | getOptions(): DataOptions; | Returns setting information. |
getOrgFieldName(fieldIndex) | getOrgFieldName(fieldIndex: number): string; | Returns the original name of the field at a specific index. |
getOrgFieldNames() | getOrgFieldNames(): string[]; | Returns the original names of the fields. |
getRowState(row) | getRowState(row: number): RowState; | Returns the status of the specified row. |
getRowStateCount(states) | getRowStateCount(states: string | RowState | RowState[]): number; | Returns the number of data rows for each status. |
getSavePoints() | getSavePoints(): number[]; | Returns all recovery points. |
getStateRows(rowState) | getStateRows(rowState?: RowState): number[]; | Returns data row indices with a specific status. |
getUpdatedCells(rows) | getUpdatedCells(rows: number[]): UpdatedRow[]; | Returns changed cell information of specified rows |
getValues(row) | getValues(row: number): RowValues; | Returns the values of the row. |
hasData(row) | hasData(row: number): boolean; | Returns whether the row is filled with values. |
redo() | redo(): void; | Cancel the reverted contents. |
removeField(field, resetFields) | removeField(field: DataFieldInput, resetFields?: boolean): void; | Remove field. |
restoreUpdatedRows(rows) | restoreUpdatedRows(rows: number | number[]): void; | Restores the value and status of specified rows. |
restoreUpdatedStates(rows) | restoreUpdatedStates(rows: number[]): void; | Restores the status of specified rows. |
rollback(savePoint) | rollback(savePoint?: number): void; | Restore data set |
savePoint(saveStates) | savePoint(saveStates?: boolean): number; | Record the recovery point of the data set. |
setDataComparer(field, comparer) | setDataComparer(field: string | number, comparer: CompareFunction): void; | Sets the sorting function for a specific field. |
setFields(fields) | setFields(fields: DataFieldInput[]): void; | Set fieldset |
setOptions(options) | setOptions(options: DataOptions): void; | Change setting information. |
setRowState(row, state, force) | setRowState(row: number, state?: RowState, force?: boolean): void; | Change the status of a specific row. |
setRowStates(rows, state, force, rowEvents) | setRowStates(rows: number[], state?: RowState, force?: boolean, rowEvents?: boolean): void; | Change the status of multiple rows at once. |
undo() | undo(): void; | Reverts previously modified content. |
Construct Desc
(constructor)
Constructs a new instance of the DataProviderBase
class
Properties Desc
amText
String corresponding to AM in data
Type
- string
Example:
ds.amText = "AM";
baseYear
Year based on 2-digit data year
Type
- number
Example:
ds.baseYear = 1000;
booleanFormat
Format for parsing data into Boolean
Type
- string
Example:
ds.booleanFormat = 'No: Yeah';
checkStates
Whether row state management is enabled or not
Type
- boolean
Example:
ds.checkStates = false;
commitBeforeDataEdit
Whether to automatically commit the previous edit when calling a change function (setValue()
, etc.) for another row while in edit state.
Type
- boolean
Example:
ds.commitBeforeDataEdit = true;
datetimeFormat
Format for parsing date data in text format into datetime values
Type
- string
Example:
ds.datetimeFormat = 'yyyy-MM-dd';
deletable
Can rows be deleted?
Type
- boolean
Example:
ds.deletable = false;
deleteCreated
Whether to actually delete the added row when deleting it
Type
- boolean
Example:
ds.deleteCreated = false;
insertable
Whether rows can be inserted
Type
- boolean
Example:
ds.insertable = false;
pmText
String corresponding to afternoon in data
Type
- string
Example:
ds.pmText = "afternoon";
restoreMode
restoration mode
Type
- RestoreMode
Example:
ds.restoreMode = 'explicit';
softDeleting
When deleting a row, whether to change the RowState without actually deleting it.
Type
- boolean
Example:
ds.softDeleting = false;
strictRestore
When restoring, whether to recognize undefined
, null
, and empty strings as different values.
Type
- boolean
Example:
ds.strictRestore = true;
subTypeEnabled
Whether the subType property of DataField is enabled or not.
Type
- boolean
Example:
ds.subTypeEndabled = false;
undoable
Whether to use undo/redo
Type
- boolean
Example:
ds.undoable = true;
updatable
Can rows be modified?
Type
- boolean
Example:
ds.updatable = false;
valuesCallback
A callback called for each row when data in json format is entered into the data provider.
Type
- ObjectToValuesCallback
Remarks:
Method Desc
addField
Create additional fields.
[Parameter List]
field
- DataFieldInput
Information value of the data field to be created, if it is a string, set to fieldName
resetFields
- boolean
Whether to update field information bound to the data column
calculateData
- boolean
Whether to recalculate calculated fields
[Return Value] - DataField
Remarks:
Create a DataField object and add it to the existing fieldset.
Example:
// string
ds.addField('fieldName');
// model
let fields = ds.getFields();
ds2.addField(fields);
//config
ds.addField({
fieldName: 'OrderID',
dataType: 'text',
});
beginUpdate
Specifies the starting point of batch update.
Remarks:
When a change operation occurs in the DataProvider, it is processed by passing an event to the View. During batch processing, events occur frequently, which can reduce performance. When beginUpdate() is called, the event does not occur until endUpdate() is called, and it occurs all at once when endUpdate() is called. beginUpdate ~ endUpdate can be nested, but must be called in pairs, and the event is delivered to the View when endUpdate of the last pair is called.
Example:
dataProvider.beginUpdate();
try {
for (var i = 0; i < 10; i++) {
var values = gridView.getValues(i);
dataProvider.addRow(values);
}
} finally {
dataProvider.endUpdate();
}
checkRowStates
Specifies whether to record row status.
[Parameter List]
value
- boolean
Whether to record row status
[Return Value] - void
Remarks:
Determines whether to record the status when the row add/edit/delete status changes. If it is not recorded, it is ignored and deleted even if softDeleting is true
.
Example:
let checkState = ds.checkRowStates(true);
clearCommandStack
Initialize the Command Stack.
Example:
ds.clearCommandStack();
clearRowStates
Removes the state of all rows.
[Parameter List]
deleteRows
- boolean
Whether to actually delete a row whose row status is deleted. If true
, it is removed from the data set. If false
, the row state is reset and the data is preserved.
rowEvents
- boolean
Whether to generate state change callbacks such as onRowStateChanged for rows whose state has been removed.
[Return Value] - void
Remarks:
Initializes the state of all data rows to RowState.NONE.
Example:
ds.clearRowState(true);
clearSavePoints
Remove all recovery points.
Remarks:
Deletes all recovery points and related saved data and status.
Example:
ds.clearSavePoints();
destroy
Releases the DataProvider object from memory.
Remarks:
Remove objects and data used inside the DataProvider and enable garbage collection.
Example:
ds.destroy();
endUpdate
Specifies the completion point of batch update.
Remarks:
When a change operation occurs in the DataProvider, it is processed by passing an event to the View. During batch processing, events occur frequently, which can reduce performance. When beginUpdate() is called, the event does not occur until endUpdate() is called, and it occurs all at once when endUpdate() is called. beginUpdate ~ endUpdate can be nested, but must be called in pairs, and the event is delivered to the View when endUpdate of the last pair is called.
Example:
dataProvider.beginUpdate();
try {
for (var i = 0; i < 10; i++) {
var values = gridView.getValues(i);
dataProvider.addRow(values);
}
} finally {
dataProvider.endUpdate();
}
exportToCsv
Export the data set as a CSV file.
[Parameter List]
options
- DataExportOptions
Export Settings
[Return Value] - void
Remarks:
Depending on the options settings, the data saved in the data set is exported to a CSV file.
Since this is an export at the data level, it is carried out regardless of the status set in the View.
Example:
ds.exportToCsv();
fieldByName
Returns the field corresponding to the name.
[Parameter List]
name
- string
The value corresponding to the fieldName of the field
[Return Value] - DataField
Example:
let field = ds.fieldByName('Fruits');
getAllStateRows
Returns the index of all rows with a status value.
Remarks:
RowState.NONE Arranges the numbers of non-rows by state and returns them in Object form.
Example:
let rows = ds.getAllStateRows();
getDataRowId
Gets the internally managed dataRowId.
[Parameter List]
dataRow
- number
dataRow
[Return Value] - number
Remarks:
Internal dataRowId that does not change even when adding/deleting rows
getDistinctValues
Returns non-duplicate values of the field.
[Parameter List]
field
- string | number
Field name or field index
maxCount
- number
Maximum number of cases, sorted, cut by the number of cases from the top and returned. Default: -1
sortDir
- SortDirection
sorting method,Default: SortDirection.ASCENDING
[Return Value] - any[]
Remarks:
Returns the values corresponding to the specified field in the data set in a sorted state, excluding duplicates.
Example:
ds.getDistinctValues('field1');
getFieldCount
Returns the number of currently configured fieldsets.
Example:
let fCount = ds.getFieldCount();
getFieldIndex
Returns the index corresponding to the field name.
[Parameter List]
fieldName
- string
Field names are not case sensitive.
[return value] - number
Example:
let index = ds.getFieldIndex('fieldName');
getFieldName
Returns the name of the field at a specific index.
[Parameter List]
fieldIndex
- number
field index
[return value] - string
Remarks:
Returns the fieldName property of the field located at fieldIndex in the fieldset.
Since fieldName is internally stored in uppercase letters, it is output as an uppercase string.
To retrieve the fieldName at the time of setting, use getOrgFieldName().
Example:
let fieldName = ds.getFieldName(3);
getFieldNames
Returns the names of fields.
Remarks:
Returns the fieldName properties of fields in a fieldset as an array.
Since fieldName is internally stored in uppercase letters, it is output as an uppercase string.
To retrieve the fieldName at the time of setting, use getOrgFieldNames().
Example:
let fieldNames = ds.getFieldNames();
getFields
DataField Returns objects.
Remarks:
Returns the DataField object set in the current DataProvider as an array.
Example:
let fields = ds.getFields();
ds2.setFields(fields);
getOptions
Returns setting information.
Remarks:
Setting information is returned in the form of DataOptions.
Example:
let options = ds.getOptions();
options. undoable = true;
ds.setOptions(options);
getOrgFieldName
Returns the original name of the field at a specific index.
[Parameter List]
fieldIndex
- number
index of field
[return value] - string
Example:
let fieldName = ds.getOrgFieldName(3);
getOrgFieldNames
Returns the original names of the fields.
Example:
let orgFieldNames = ds.getOrgFieldNames();
getRowState
Returns the status of the specified row.
[Parameter List]
row
- number
Unique row number in the data set
[Return Value] - RowState
Example:
let rowState = ds.getRowState(4);
getRowStateCount
Returns the number of data rows for each status.
[Parameter List]
states
- string | RowState | RowState[]
If you want to know the status of a row, an array of statuses if there are multiple, or all statuses, use the string 'all' or '*'.
[return value] - number
Remarks:
Returns the number of rows for each status included according to the specified status array or string.
When '*'
, 'all'
is entered, all are returned.
Example:
var allStateCount = dataProvider.getRowStateCount('all');
var updateCount = dataProvider.getRowStateCount(RealGrid.RowState.UPDATED);
getSavePoints
Returns all recovery points.
Remarks:
Returns the indices of all saved recovery points as an array.
Example:
ds.getSavePoints([0, 1, 2]);
getStateRows
Returns data row indices with a specific status.
[Parameter List]
rowState
- RowState
Row state, RowState model
[return value] - number[]
Remarks:
Returns the indices of rows with the specified rowState value as an array.
Example:
let rows = ds.getStateRows('c');
getUpdatedCells
Returns changed cell information for specified rows.
[Parameter List]
rows
- number[]
Array of rows from which to retrieve information on changed cells. If null
, returns information on all rows whose status is RowState.UPDATED .
[Return value] - UpdatedRow[]
Remarks:
When the restoreMode property is RestoreMode.EXPLICIT or AUTO, information on cells in which the value of each specified row has changed is returned.
Example:
let cells = ds.getUpdatedCells([1]);
// converted data example)
[
{
__rowId: 1;
updatedCells: [
{
fieldName: 'OrderID',
oldValue: '1002',
newValue: '1003',
},
{
fieldName: 'OrderCount',
oldValue: 20;
newValue: 30
}
]
}
]
getValues
Returns the values of the row.
[Parameter List]
row
- number
Unique row number of data set
[Return Value] - RowValues
Remarks:
Returns the values of the corresponding data row as an array.
Example:
let val = ds.getValeus(5);
hasData
Returns whether the row is filled with values.
[Parameter List]
row
- number
Unique row number in the dataset
[return value] - boolean
Remarks:
Returns whether the specified data row is filled with values or is empty.
Example:
let has = ds.hasData(5);
redo
Cancel the reverted contents.
Example:
ds.redo();
removeField
Remove field.
[Parameter List]
field
- DataFieldInput
Name of the field or DataField object to remove
resetFields
- boolean
Whether to update field information bound to the data column
[Return Value] - void
restoreUpdatedRows
Restores the value and status of specified rows.
[Parameter List]
rows
- number | number[]
Index or array of indices of the row you want to restore
[Return Value] - void
Remarks:
When the restoreMode property is RestoreMode.EXPLICIT or AUTO, the changes and status of the specified rows are restored to their original state.
Example:
ds.restoreUpdatedRows([2, 4]);
restoreUpdatedStates
Restores the status of specified rows.
[Parameter List]
rows
- number[]
Array of data row indices whose state you want to restore
[Return Value] - void
Remarks:
When the restoreMode property is RestoreMode.EXPLICIT, the state of the row whose value has been changed is restored. For example, if you edit a row whose state is RowState.NONE and change it to RowState.UPDATED, then call it after the row's value returns to its original state. The state is restored to RowState.NONE. When restoreMode is AUTO, it is automatically restored according to row values.
Example:
ds.restoreUpdatedStates([2, 4]);
rollback
Restore the data set
[Parameter List]
savePoint
- number
Index of recovery point, default: 0
[Return Value] - void
Remarks:
Returns the data and status of the data set to the point in time.
Example:
ds.rollback();
savePoint
Record the recovery point of the data set.
[Parameter List]
saveStates
- boolean
Status recorded?
[return value] - number
Remarks:
Copies and stores the data and state of the data set and returns the index of the point. After this, you can return to a specific point through the rollback() function.
Example:
ds.savePoint([2, 4]);
setDataComparer
Sets the sorting function for a specific field.
[Parameter List]
field
- string | number
Name or index of the field to specify sorting method
comparer
- CompareFunction
custom sort function
[Return Value] - void
Remarks:
When sorting of the field occurs, set a user-defined sort function rather than the sort function used by default. The sort function is identical to the compareFunction of JavaScript Array.prototype.sort().
Example:
dataProvider.setDataComparer('OrderID', function(field, row1, row2) {
var val1 = dataProvider.getValue(row1, field);
var val2 = dataProvider.getValue(row2, field);
return val1 == val2 ? 0 : val1 > val2 ? 1:-1;
}
setFields
Set the fieldset
[Parameter List]
fields
- DataFieldInput[]
Array of information in the DataField to be created
[Return Value] - void
Remarks:
Deletes existing field information and bound data and constructs a new field set from the received field information array. Creates DataField objects as many as the number of fields. If the element is a string, it is created by fieldName. If the element is a DataField, it is duplicated. If the element is DataFieldObject, it is created based on the property value. do.
Example:
// string
ds.setFields('fieldName');
// model
let fields = ds.getFields();
ds.setFields(fields);
//config
ds.setFields({
fieldName: 'OrderID',
dataType: 'text',
});
setOptions
Change setting information.
[Parameter List]
options
- DataOptions
DataOptions Setting information object
[Return Value] - void
Remarks:
Settings not entered in options retain their original values.
Example:
let options = {
insertable: true;
updatable: true;
softDeleting: false
};
ds.setOptions(options);
setRowState
Change the status of a specific row.
[Parameter List]
row
- number
Index of the data row whose state will be changed
state
- RowState
State to change, default: RowState.NONE
force
- boolean
Applies regardless of DataProvider's state management; default: false
[Return Value] - void
Example:
ds.setRowState(5, 'updated');
setRowStates
Change the status of multiple rows at once.
[Parameter List]
rows
- number[]
Array of data row indices to change state
state
- RowState
state to change
force
- boolean
Applies regardless of DataProvider's state management
rowEvents
- boolean
If true
, a state change event for each data row occurs. If false
, it occurs as a single event.
[Return Value] - void
Remarks:
Batch changes the status of data rows passed in an array.
Example:
ds.setRowStates([1,3,5], "updated");
undo
Reverts previously modified content.
Example:
ds.undo();