TableSheet provides the ability to add, update and remove a column with the meaningful column types(Number, Text, Formula, Lookup, Date, Checkbox, Select, Currency, Percent, Phone, Email, URL, CreatedTime, ModifiedTime, Attachment, Barcode) to a table which will help the customer to design the table easily.
The TableSheet lets users enable defining column by the options which will toggle the visibility of the add column button, modify column, remove column and set primary key context menu on the column header:
interface GC.Spread.Sheets.TableSheet.ITableSheetOptions {
// other properties...
enableDefineColumn?: boolean;
}
Column Types
interface GC.Data.IColumn {
type: string, // the built-in column types: Number, Text, Formula, Checkbox, Date, Currency, Percent, Phone, Email, URL, Lookup, CreatedTime, ModifiedTime, Attachment, Select, Barcode
}
The descriptions of the supported column types:
Column Type | Data Type | Description |
---|---|---|
Number | number | For most numerical values with specified formatting |
Text | string | For the common text |
Formula | depends on the result | To compute a value based on other fields in the record. |
Lookup | depends on the related | To look up a specific field in a related record. |
Date | date | To easily enter a date value |
Checkbox | boolean | Useful to check/uncheck with a TRUE/FALSE data type |
Select | depends on the option | Useful to select an option from a preset list |
Currency | number | Indicates the currency with culture formatting |
Percent | number | Indicates the number formatted as the percent |
Phone | string | Indicates the digit string of numbers with mask validation |
string | Indicates the email address with mask validation | |
URL | string | Indicates the URL text |
CreatedTime | date | To set a date when the record create |
ModifiedTime | date | To set a date when the fields updated in the record |
Attachment | object | Allows to attach a file directly on the record |
Barcode | depends on the input | Generates a specified barcode from the field |
Configuration
To communicate with the table, it should configure the remote APIs:
Column API | Description |
---|---|
getColumns | Retrieve the columns from the table |
addColumn | Add a column to the table |
updateColumn | Update the properties of a column to the table |
removeColumn | Remove a column from the table |
batch | The changes will post together in the batch mode |
var apiForDataUrl = './orders', apiForColumnUrl = './tables/order/columns';
var orderTable = dataManager.addTable("orderTable", {
remote: {
read: {
url: apiForDataUrl,
},
update: {
url: apiForDataUrl,
method: 'PUT'
},
create: {
url: apiForDataUrl,
},
delete: {
url: apiForDataUrl,
},
getColumns: {
url: apiForColumnUrl
},
addColumn: {
url: apiForColumnUrl,
method: 'POST'
},
updateColumn: {
url: apiForColumnUrl,
method: 'PUT'
},
removeColumn: {
url: apiForColumnUrl,
method: 'DELETE'
},
// batch: {
// url: './batch',
// }
},
autoSync: true,
// batch: true
});
And the column remote APIs could be handled by the self-defined functions which are similar as the Handle Requests.
Request and Response
type Column = {
field: string, // the name of the field
dataType: 'number' | 'string' | 'boolean', // the data type could be converted to another data type on the remote storage source
defaultValue?: 'number' | 'string' | 'boolean' | 'undefined', // the static default value for remote storage source
isPrimaryKey?: boolean, // indicates the field could be the primary
}
type ColumnData = {
column: Column,
}
type ColumnWithDefaultData = {
column: Column,
data?: any[], // in some cases, the data provided by the client should sync to the remote storage source, for example, the column with a formula default value is added to the table has some records
}
type ModifiedColumnData = {
column: Column,
originalColumn: Column,
}
type BatchItemData = {
type: "updateColumn" | "addColumn" | "removeColumn", // it only shows the options about the column changes, the whole changes include the column and data if exited
column: Column,
data?: any[],
originalColumn?: Column,
}
type BatchResultData = {
succeed: boolean,
reason?: string,
}
Operation | Request Data | Response Data |
---|---|---|
getColumns | None | Column[] |
addColumn | ColumnWithDefaultData | ColumnData |
updateColumn | ModifiedColumnData | ModifiedColumnData |
removeColumn | ColumnData | ColumnData |
batch | BatchItemData[] | BatchResultData[] |
The Commands
Besides defining through UI, there are also the commands to define the columns:
DefineColumn
The DefineColumn command could add a column:
/**
* GC.Spread.Sheets.Commands.DefineColumn: { canUndo: boolean, execute(context: GC.Spread.Sheets.Workbook, options: {sheetName: string, col?: number, column: GC.Data.IColumn}): any}
* Represents the command used to define the column.
* @property {boolean} canUndo - indicates whether the command supports undo and redo operations.
* @property {function} execute - performs an execute or undo operation.
* The arguments of the execute method are as follows.
* @param {GC.Spread.Sheets.Workbook} context The context of the operation.
* @param {Object} options The options of the operation.
* @param {string} options.sheetName The sheet name.
* @param {number} [options.col] The specified col for inserting, optional.
* @param {GC.Data.IColumn} options.column The defined column.
* @param {boolean} isUndo `true` if this is an undo operation; otherwise, `false`.
*/
spread.commandManager().execute({
cmd: "DefineColumn",
sheetName: spread.getActiveSheetTab().name(),
// col: 3, // optional
column: {
type: 'Number', // specify the column type
value: 'Number1', // the column identifier of the column instance from the column type
caption: '# Number1', // the display of the column for the culture
style: { formatter: '#,##0.00_);[Red](#,##0.00)' } // the formatter could be specified or be converted from the UI operations
} as GC.Data.IColumn,
});
ModifyColumn
The ModifyColumn command could change the column properties:
/**
* field GC.Spread.Sheets.Commands.ModifyColumn: { canUndo: boolean, execute(context: GC.Spread.Sheets.Workbook, options: {sheetName: string, col: number, column: GC.Data.IColumn}): any}
* Represents the command used to modify the column.
* @property {boolean} canUndo - indicates whether the command supports undo and redo operations.
* @property {function} execute - performs an execute or undo operation.
* The arguments of the execute method are as follows.
* @param {GC.Spread.Sheets.Workbook} context The context of the operation.
* @param {Object} options The options of the operation.
* @param {string} options.sheetName The sheet name.
* @param {number} options.col The specified col.
* @param {GC.Data.IColumn} options.column The modified column.
* @param {boolean} isUndo `true` if this is an undo operation; otherwise, `false`.
*/
spread.commandManager().execute({
cmd: "ModifyColumn",
sheetName: spread.getActiveSheetTab().name(),
col: 3,
column: {
type: 'Text', // specify the column type
value: 'Text1', // the column identifier of the column instance from the column type
caption: 'A Text1', // the display of the column for the culture
} as GC.Data.IColumn,
});
RemoveColumn
The RemoveColumn command could remove the column:
/**
* field GC.Spread.Sheets.Commands.RemoveColumn: { canUndo: boolean, execute(context: GC.Spread.Sheets.Workbook, options: {sheetName: string, col: number}): any}
* Represents the command used to remove the column.
* @property {boolean} canUndo - indicates whether the command supports undo and redo operations.
* @property {function} execute - performs an execute or undo operation.
* The arguments of the execute method are as follows.
* @param {GC.Spread.Sheets.Workbook} context The context of the operation.
* @param {Object} options The options of the operation.
* @param {string} options.sheetName The sheet name.
* @param {number} options.col The specified col.
* @param {boolean} isUndo `true` if this is an undo operation; otherwise, `false`.
*/
spread.commandManager().execute({
cmd: "RemoveColumn",
sheetName: spread.getActiveSheetTab().name(),
col: 3,
});
Submit and view feedback for