Cell Module
The Cell module can be understood as a cell in a table view. It can get/set value. There are several ways to retrieve a cell:
- Create a
Cellby using a field. In this case, theCellis not inserted into aTable, so setting/getting values will not affect the table. The main purpose of this type ofCellis to be used as a parameter foraddRecord/addRecords.
const cell = await field.createCell(val);const cell = await field.createCell(val);- Get a
Cellby using aField. In this case, theCellis retrieved from theTable, so setting/getting values will affect the table. Setting a value will update the corresponding data in theTable.
const cell = await field.getCell(recordOrId);const cell = await field.getCell(recordOrId);- Get a
Cellby using aRecord. There are two interfaces in aRecordthat can be used to retrieve aCell. TheCellobtained through theRecordis associated with theTable, so setting/getting values will affect the table.
const cellList = await record.getCellList();
const cell = await record.getCellByField(fieldOrId);const cellList = await record.getCellList();
const cell = await record.getCellByField(fieldOrId);It is recommended to use the Field to perform operations on the Cell, as it provides better type hints and autocomplete suggestions for each Cell type. For example:
const attachmentCell = await attachmentField.getCell(recordOrId);
await attachmentCell.setValue(newImageFile);const attachmentCell = await attachmentField.getCell(recordOrId);
await attachmentCell.setValue(newImageFile);After obtaining the cell through attachmentField, the setValue method will inform developers that they can pass in File/File[]/FileList to set the value.
Cell can be created using the createCell method of a Field. The created Cell can be used as a parameter for addRecord, making it convenient to insert data. Using a Cell to insert data is also a recommended practice (thinking about data manipulation from the perspective of fields):
const attachmentCell = await attachmentField.createCell(imageFileList);
const singleSelectCell = await singleSelectField.createCell('option1');
const recordId = await table.addRecord([attachmentCell, singleSelectCell]);const attachmentCell = await attachmentField.createCell(imageFileList);
const singleSelectCell = await singleSelectField.createCell('option1');
const recordId = await table.addRecord([attachmentCell, singleSelectCell]);editable
editable: boolean;editable: boolean;In a multi-dimensional table, not all fields support editing (e.g., creator/creation time fields). This property can be used to check if a field is editable.
setValue
setValue: (val: V) => Promise<void | boolean>;setValue: (val: V) => Promise<void | boolean>;Sets the value of a cell. If the cell is already inserted into a Table, the value in the Table will be updated in real-time.
getValue
getValue: () => Promise<R>;getValue: () => Promise<R>;Gets the value of a cell. If the cell is already inserted into a Table, it will retrieve the value from the Table.
getFieldId
getFieldId: () => string;getFieldId: () => string;Gets the ID of the field to which the current cell belongs.