[]
• new Table(name
, dataSourceOption
)
Represents the table.
Name | Type | Description |
---|---|---|
name |
string |
The table name. |
dataSourceOption |
IDataSourceOption |
The data source of table. |
• columns: IColumnCollection
Represents the default columns of the table, it is only available after table is fetched. The key is column name, the value is column information.
• name: string
Represents the name of the table.
• options: IDataSourceOption
Represents the data source options of the table.
• views: IViews
Represents the view collection of the table. The key is view name, the value is GC.Data.View instance.
▸ addView(name
, columnInfos?
, includeDefaultColumns?
, options?
): View
Adds a view, which host table is current table.
property
name - The unique name of the column.
property
[value] - The value of the column, could be a field name of table from database, or formula which uses the fields names.
property
{string | string[]} [caption] - The caption of the column.
property
{number | string} [width] - The width of the column, support number in pixel, or star size.
property
[style] - The column style options.
property
{(GC.Data.CellValueRuleOptions | GC.Data.SpecificTextRuleOptions | GC.Data.FormulaRuleOptions | GC.Data.DateOccurringRuleOptions | GC.Data.Top10RuleOptions | GC.Data.UniqueRuleOptions | GC.Data.DuplicateRuleOptions | GC.Data.AverageRuleOptions | GC.Data.TwoScaleRuleOptions | GC.Data.ThreeScaleRuleOptions | GC.Data.DataBarRuleOptions | GC.Data.IconSetRuleOptions)[]} [conditionalFormats] - The conditional rules array.
property
{GC.Data.NumberValidatorOptions | GC.Data.DateValidatorOptions | GC.Data.TimeValidatorOptions | GC.Data.TextLengthValidatorOptions | GC.Data.FormulaValidatorOptions | GC.Data.FormulaListValidatorOptions | GC.Data.ListValidatorOptions} [validators] - The default data validator.
property
[isPrimaryKey] - Mark the column as primary key column.
property
[readonly] - Mark the column is readonly.
property
[required] - Mark the column is required when insert a new row.
property
[defaultValue] - Provide the default value when insert a new row, could be a const or a formula.
property
[style] - The column header style options.
example
// Add a view by string array columns
productTable.addView("productView", [
"id", "name", "reorderLevel", "unitPrice", "unitsInStock", "unitsOnOrder"
]);
// Add a view by customized columns
productTable.addView("productView", [{
value: "id",
caption: "ID",
isPrimaryKey: true
}, {
value: "name",
caption: "NAME",
required: true
}, {
value: "quantityPerUnit",
caption: "QUANTITY PER UNIT"
}, {
value: "unitPrice",
caption: "UNIT PRICE"
}, {
value: "unitsInStock",
caption: "UNITS IN STOCK",
readonly: true
}, {
value: "unitsOnOrder",
caption: "UNITS ON ORDER"
}, {
value: "reorderLevel",
caption: "REORDER LEVEL"
}, {
value: "discontinued",
caption: "DISCONTINUED",
defaultValue: false
});
// Add a view with relationship columns
var supplierRelationship = dataManager.addRelationship(productTable, "supplierId", "supplier", supplierTable, "id", "products");
productTable.addView("productWithSupplierView", [{
value: "id",
caption: "ID"
}, {
value: "name",
caption: "NAME"
}, {
value: "supplier.companyName", // relationship
caption: "SUPPLIER NAME"
}, {
value: "supplier.contactName", // relationship
caption: "SUPPLIER CONTACT NAME"
}, {
value: "supplier.contactTitle", // relationship
caption: "SUPPLIER CONTACT TITLE"
});
// Add a view with calc field columns
var supplierRelationship = dataManager.addRelationship(productTable, "supplierId", "supplier", supplierTable, "id", "products");
productTable.addView("productWithSupplierView", [{
value: "id",
caption: "ID"
}, {
value: "name",
caption: "NAME"
}, {
caption: "TOTAL PRICE",
value: "=(unitsInStock + unitsOnOrder) * unitPrice"
}, {
caption: "SUPPLIER'S INFO",
value: "=CONCAT(supplierTable.companyName, ', ', supplierTable.contactName)"
});
Name | Type | Description |
---|---|---|
name |
string |
The view name. |
columnInfos? |
string [] | IColumn [] |
- |
includeDefaultColumns? |
boolean |
Whether to include current table's default columns when column information are empty. Its default value is true. |
options? |
ViewOptions |
- |
Returns the view.
▸ clearIndexes(): void
Clear all the indexed fields.
example
// Clear all the indexed fields.
table.clearIndexes();
void
▸ createIndexes(fields
): void
Create index for the fields.
example
// Create indexes.
table.createIndexes(["name", "country", "project"]);
Name | Type | Description |
---|---|---|
fields |
string [] |
The index fields. |
void
▸ dropIndexes(fields
): void
Drop indexed fields.
example
// Drop indexed fields.
table.dropIndexes(["name", "country", "project"]);
Name | Type | Description |
---|---|---|
fields |
string [] |
The indexed fields. |
void
▸ fetch(reload?
): Promise
<any
>
Requests the table data from local data source or remote data source by the data source option.
example
// Use fetched data to build a tablesheet
productTable.fetch().then(function(data) {
var productView = productTable.addView("productView");
var tableSheet = spread.addSheetTab(0, "productTableSheet", GC.Spread.Sheets.SheetType.tableSheet);
tableSheet.setDataView(productView);
});
Name | Type |
---|---|
reload? |
boolean |
Promise
<any
>
The resolving Promise thenable. You could get the data in Promise.then().
▸ getIndexes(): string
[]
Get all the indexed fields.
example
// Indexed fields exist.
table.getIndexes(); // returns ["name", "country", "project"]
// No indexed field.
table.getIndexes(); // returns []
string
[]
The indexed fields.
▸ removeView(name
): void
Removes a view.
example
// Remove a view by name
dataManager.removeView("productView");
Name | Type | Description |
---|---|---|
name |
string |
The name of the view to be removed. |
void
▸ search(value
, field
): any
[]
Search the records with search value, returns all the exact matching records.
example
// Search value and succeed
table.search("SpreadJS", "group"); // returns [ {id: 1, project: "DataManager", group: "SpreadJS"}, {id: 3, project: "TableSheet", group: "SpreadJS"} ]
// Search value and failed
table.search("WPS", "project"); // returns []
Name | Type | Description |
---|---|---|
value |
any |
The search value. Always convert the non-string to string type. |
field |
string |
The target field. |
any
[]
The all matching records.