SpreadJS TableSheet gives the user the ability to provide a data source schema that defines the structure and properties of the TableSheet being added. The user can also use the data source schema to assign a different dataType for columns or a dataPattern/dataMap on how the data would be presented in the TableSheet.
The schema contains the following properties:
Property | Type | Description |
---|---|---|
type | string | Any of 'json', 'csv', 'xml', 'columnJson'. |
countPath | string | The data reader uses this to get the data source collection length. |
dataPath | string | The data reader uses this to get the data source collection after parse. |
columns | GC.Data.IColumnCollection | The columns definitions of the data source table. Its key is column name, and its value is the column information, which contains dataType, dataPattern, dataMap and dataName. |
The dataType can be a "string", "number", "boolean", "object", "array", "date", "rowOrder" or "formula". It is the actual data type of original value, and useful for a Date because a Date is a string in JSON data and needs be converted.
The dataPattern is a string for parsing strings to value, such as the formatter "dd/MM/yyyy" for a date string, true and false value pairs, "Yes|No" for a boolean string, and decimal separator "," for a numeric string.
The dataMap is a simple map to display the original value in a more meaningful way. Its key can be a number or string, and its value can be a number, string or Date.
The dataName indicates the name of the original data field that be from data source, using this property can map the original field name to the new field name in the data manager.
interface GC.Data.IColumnCollection {
[key: string]: GC.Data.IColumn;
}
interface GC.Data.IColumn {
dataName?: string;
dataType?: "string" | "number" | "boolean" | "object" | "array" | "date" | "rowOrder" | "formula";
dataPattern?: string;
dataMap?: any;
}
This is the sample code of type, dataPath and countPath.
var myTable = dataManager.addTable("myTable", {
remote: {
read: {
url: 'https://services.odata.org/OData/OData.svc/Products/',
adapter: 'odata'
}
},
schema: {
type: 'xml',
dataPath: 'feed.entry',
countPath: 'feed.entry.length'
}
});
This is the sample code for dataType and dataMap.
var myTable = dataManager.addTable("myTable", {
remote: {
read: {
url: "https://demodata.mescius.io/northwind/api/v1/Orders"
}
},
schema: {
columns: {
orderDate: {dataType: "date"},
requiredDate: {dataType: "date"},
shippedDate: {dataType: "date"},
shipVia: {dataMap: {1: "Speedy Express", 2: "United Package", 3: "Federal Shipping"}}
}
}
});
This is the sample code for dataPattern.
var myTable = dataManager.addTable("myTable", {
data: [
{ description: "Mow grass", dueDate: "8/11/2021", priority: "High", assignedTo: "Dad", isFinished: "Yes", isEncouraged: "False", credit: "20,75" },
{ description: "Clean Room", dueDate: "8/9/2021", priority: "Medium", assignedTo: "Daughter", isFinished: "No", isEncouraged: "True", credit: "10,50" },
{ description: "Organize Pantry", dueDate: "8/8/2021", priority: "Low", assignedTo: "Son", isFinished: "Yes", isEncouraged: "True", credit: "10,75" },
{ description: "Prepare BBQ", dueDate: "8/12/2021", priority: "High", assignedTo: "Mom", isFinished: "No", isEncouraged: "False", credit: "30,25" }
],
schema: {
columns: {
dueDate: {dataType: "date", dataPattern: "dd/MM/yyyy"},
isFinished: {dataType: "boolean", dataPattern: "Yes|No"},
isEncouraged: {dataType: "boolean", dataPattern: "True|False"},
credit: {dataType: "number", dataPattern: ","}
}
}
});
This is the sample code of dataName. the keys of the property columns indicate the field names in the data manager, and the dataName indicates the original data source field name.
var myTable = dataManager.addTable("myTable", {
remote: {
read: {
url: "https://demodata.mescius.io/northwind/api/v1/Orders"
}
},
schema: {
columns: {
OrderDate: {dataName: "orderDate"},
RequiredDate: {dataName: "requiredDate"},
ShippedDate: {dataName: "shippedDate"},
ShipVia: {dataName: "shipVia"}
}
}
});
Submit and view feedback for