[]
表示表。
param 表名。
param 表的数据源。
• new Table(name, dataSourceOption)
| Name | Type |
|---|---|
name |
string |
dataSourceOption |
IDataSourceOption |
• columns: IColumnCollection
表示表的默认列,仅在获取表后可用。键是列名,值是列信息。
• name: string
表示表的名称。
• options: IDataSourceOption
表示表的数据源选项。
• views: IViews
表示表的视图集合。键是视图名,值是GC.Data.View实例。
▸ addView(name, columnInfos?, includeDefaultColumns?, options?): View
添加一个视图,其宿主表是当前表。
property name - 列的唯一名称。
property [value] - 列的值,可以是数据库中表的字段名,或使用字段名的公式。
property {string | string[]} [caption] - 列的标题。
property {number | string} [width] - 列的宽度,支持以像素为单位的数字,或星号大小。
property [style] - 列样式选项。
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] - 条件规则数组。
property {GC.Data.NumberValidatorOptions | GC.Data.DateValidatorOptions | GC.Data.TimeValidatorOptions | GC.Data.TextLengthValidatorOptions | GC.Data.FormulaValidatorOptions | GC.Data.FormulaListValidatorOptions | GC.Data.ListValidatorOptions} [validators] - 默认数据验证器。
property [isPrimaryKey] - 将列标记为主键列。
property [readonly] - 标记列是只读的。
property [required] - 标记插入新行时列是必需的。
property [defaultValue] - 插入新行时提供默认值,可以是常量或公式。
property [style] - 列标题样式选项。
example
// 通过字符串数组列添加视图
productTable.addView("productView", [
"id", "name", "reorderLevel", "unitPrice", "unitsInStock", "unitsOnOrder"
]);
// 通过自定义列添加视图
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
});
// 添加带有关系列的视图
var supplierRelationship = dataManager.addRelationship(productTable, "supplierId", "supplier", supplierTable, "id", "products");
productTable.addView("productWithSupplierView", [{
value: "id",
caption: "ID"
}, {
value: "name",
caption: "NAME"
}, {
value: "supplier.companyName", // 关系
caption: "SUPPLIER NAME"
}, {
value: "supplier.contactName", // 关系
caption: "SUPPLIER CONTACT NAME"
}, {
value: "supplier.contactTitle", // 关系
caption: "SUPPLIER CONTACT TITLE"
});
// 添加带有计算字段列的视图
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 |
视图名。 |
columnInfos? |
string[] | IColumn[] |
- |
includeDefaultColumns? |
boolean |
当列信息为空时是否包含当前表的默认列。其默认值为true. |
options? |
ViewOptions |
- |
返回该视图。
▸ clearIndexes(): void
清除所有索引字段。
example
// 清除所有索引字段。
table.clearIndexes();
void
▸ createIndexes(fields): void
为字段创建索引。
example
// 创建索引。
table.createIndexes(["name", "country", "project"]);
| Name | Type | Description |
|---|---|---|
fields |
string[] |
索引字段。 |
void
▸ dropIndexes(fields): void
删除索引字段。
example
// 删除索引字段。
table.dropIndexes(["name", "country", "project"]);
| Name | Type | Description |
|---|---|---|
fields |
string[] |
已索引的字段。 |
void
▸ fetch(reload?): Promise<any>
根据数据源选项从本地数据源或远程数据源请求表数据。
example
// 使用获取的数据构建集算表
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>
解析的Promise thenable。您可以在Promise.then()中获取数据。
▸ getIndexes(): string[]
获取所有索引字段。
example
// 存在索引字段。
table.getIndexes(); // 返回 ["name", "country", "project"]
// 没有索引字段。
table.getIndexes(); // 返回 []
string[]
索引字段。
▸ removeView(name): void
移除一个视图。
example
// 按名称移除视图
dataManager.removeView("productView");
| Name | Type | Description |
|---|---|---|
name |
string |
要移除的视图名称。 |
void
▸ search(value, field): any[]
使用搜索值搜索记录,返回所有精确匹配的记录。
example
// 搜索值并成功
table.search("SpreadJS", "group"); // 返回 [ {id: 1, project: "DataManager", group: "SpreadJS"}, {id: 3, project: "TableSheet", group: "SpreadJS"} ]
// 搜索值但失败
table.search("WPS", "project"); // 返回 []
| Name | Type | Description |
|---|---|---|
value |
any |
搜索值。始终将非字符串转换为字符串类型。 |
field |
string |
目标字段。 |
any[]
所有匹配的记录。