It is not only a fully functional graph visualization library, but also an explorer of data relationships.
!!!###!!!title=edit cell——VisActor/VTable tutorial documents!!!###!!!!!!###!!!description=When it comes to business scenarios of editing tables, the VTable library provides corresponding editors so that you can easily implement various editing needs.!!!###!!!
Edit cell
When it comes to business scenarios of editing tables, the VTable library provides corresponding editors so that you can easily implement various editing needs.
Steps for usage
1. Reference the editor package of VTable:
Use the NPM package
First, make sure you have installed the VTable library and related editor packages correctly. You can install them using the following command:
Introduce the required type of editor module into your code:
use CDN
你还可以通过 CDN 获取构建好的 VTable-Editor 文件。
2. Create editor:
The VTable-ediotrs library currently provides four editor types, including text input boxes, textarea input boxes, date pickers, drop-down lists, etc. You can choose the appropriate editor according to your needs.
Here is sample code to create an editor:
In the above example, we created a text input box editor (InputEditor), a multi-line text area editor (TextAreaEditor), a date picker editor (DateInputEditor) and a drop-down list editor (ListEditor). You can choose the appropriate editor type according to your actual needs.
3. Register and use the editor:
Before using the editor, you need to register the editor instance into VTable:
Next, you need to specify the editor to use in the columns configuration(If it is a pivot table, configure the editor in indicators):
In a table, users can start editing by double-clicking a cell and then selecting the editor to use for input.
Note: The editors in the VTable library are all implemented based on the browser's native input box, so problems may occur in some special cases, such as input method input, input method pop-up windows, etc. You can adjust and optimize according to actual needs.
Editor configuration can be defined in columns or global options. It also supports custom function writing:
If the several editors provided by the VTable-ediotrs library cannot meet your needs, you can implement a custom editor. To do this, you need to create a class that implements the requirements of the editor interface (IEditor) and provides the necessary methods and logic.
You can use the following flow chart to understand the relationship between the editor and VTable:
The following is sample code for a custom editor:
In the above example, we created a custom editor named DateEditor and implemented the methods required by the IEditor interface. Then, we register the custom editor into the VTable through the VTable.register.editor method for use in the table.
VTable provides the function of editing event listening. You can listen to the editing data event and execute the corresponding logic in the event callback.
The following is a sample code for editing event listening:
6. Obtain data after editing:
When the user completes editing and submits the data, you can obtain the edited data for subsequent processing. You can directly get the records value
7. Edit trigger timing
Editing trigger timing support: double-click a cell to enter editing, click a cell to enter editing, and call the API to manually start editing.
8. Edit value verification
If validation is required, please customize the editor to implement the validation function validateValue
If this interface is not defined, the edit value will not be checked by default; Support the following return values:
true: The verification passes, and the editing state is exited.
false: The verification fails, and the editing state is retained.
ValidateEnum.validateExit: The verification passes, and the editing state is exited.
ValidateEnum.invalidateExit: The verification fails, the editing state is exited, and the old value is retained.
ValidateEnum.validateNotExit: The verification passes, and the editing state is not exited.
ValidateEnum.invalidateNotExit: The verification fails, and the editing state is not exited.
If you need to implement asynchronous verification, you can return a Promise object, which is resolved with a true value when the verification succeeds and a false value when the verification fails.
At the same time, when pasting cell data, the validation function validateValue will also be called.
9. Related APIs
ListTable Header Editing Precautions
The basic table supports editing the display title in the header. You can enable this by configuring headerEditor globally or within a column. The usage is the same as editor.
PivotTable Editing Precautions
Editing the header of the pivot table will modify the field name in the records accordingly;
In a pivot table, when a cell in the body corresponds to only one source data record, the field value of the record will be modified accordingly after editing. However, when the cell corresponds to an indicator value that aggregates multiple records, it does not support corresponding modifications to the source data.
The source data corresponding to a specific cell can be obtained through the interface getCellOriginRecord
Summary
Through the above steps, you can create a table with editing functions, select the appropriate editor type according to business needs, customize the editor, listen to editing events, and obtain edited data. In this way, users can easily edit the data in the table, and you can process the edited data accordingly.