SpreadJS 15
Features / TableSheet / Data Manager
In This Topic
    Data Manager
    In This Topic

    The Data Manager is a powerful local data engine that sends requests to the server-side, then binds the data to the Table Sheet when data is ready.

    The Data Manager interacts with the database, manages it (sort, filter, group, aggregate), and synchronizes real-time data back to the database using the GC.Data.DataManager class. The addTable and addRelationship methods are used to map a table or relationship in the Data Manager. Similarly, you can also remove a table or relationship using the DataManager class methods.

    Data Manager serves as the data core of the application, allowing it to focus more on business logic and rendering. Remote sources such as REST API, OData, GraphQL, and local sources like object array for JSON, a string for CSV, or XML are supported to create a tablesheet.

    Data Source Schema

    You can provide a schema when you add a data source to define the data table. The schema contains the following properties:

    Property Description

    type

    string

    The data type used. One of 'JSON', 'CSV', 'XML', 'columnJson'.

    The default type is 'JSON'.

    countPath

    string

    Used to get data source collection length.

    dataPath

    string

     

    Used to get data source collection after parse.

    columns

    GC.Data.IColumnCollection

     

    The column definitions of the data source table. Its key is the column name, and its value is column information, which contains dataType, dataPattern, and dataMap.

    • The dataType is any of "string", "number", "boolean", "null", "object", "array" or "date". It is the actual data type of original value. It is especially useful for a Date because a Date is a string in JSON data and needs to be converted.
    • The dataPattern is a string for parsing a string to value, such as formatter "dd/MM/yyyy" for a date string, "truthy" and "falsy" value pairs "Yes|No" for a boolean string, decimal separator "," for a numeric string.
    • The dataMap is a simple map to display the original value in a more meaningful way. Its key could be a number or string, and its value could be a number, string, or Date.

    The following code sample shows how to set up a data schema for tablesheet.

    JavaScript
    Copy Code
    var dataManager = spread.dataManager();
    var customerTable = dataManager.addTable("customerTable", {
        remote: {
            read: {
                url: apiUrl
            }
        },
        // data source schema - here we set dataType, dataPattern , dataMap etc.
        schema: {
            columns: {
                validFrom: { dataType: "date" },
                billToCustomer: { dataMap: { "Tailspin Toys (Head Office)": "Tailspin Toys(HO)", "Wingtip Toys (Head Office)": "Wingtip Toys(HO)" } },
                buyingGroup: { dataMap: { "Tailspin Toys": "TT", "Wingtip Toys": "WT" } },
                postalCode: { dataType: "number" }
            }
        }
    });