The SpreadJS Data Manager is a powerful data engine API built for performance that makes connecting and interacting with TableSheet's bound data faster and easier than ever with data relationships and views. The Data Manager allows you to load entire data tables and easily create multiple views using specific fields from that data source, giving you much faster performance with greater flexibility than just using the standard data binding.
In this blog, I will show you how to create a basic Data Manager, add some data to it, and then bind different views to the TableSheet and display them in a SpreadJS workbook. To follow along, you can download the sample for this blog.
Before we begin, we need to install the required SpreadJS files that we need for this application using NPM:
Creating the Data Manager
The first step is to create the DataManager. With SpreadJS, this is as simple as creating a new instance of Spread, getting the data manager, and then adding tables to it:
In the case of this blog, we are just using simple JSON files that contain the data, but you could bind to your data source or read from a specific URL.
Before we can start with creating styles we will want to add relationships between the tables. To do this, we can choose specific fields from different tables and create a connection between them:
Creating Views
Before we create our views of the Data Manager, we can start by defining some styles for some of the fields, specifically combining the different shipping address fields as well as the company and contact name for the customer:
Multiple views can be defined and bound to individual TableSheets, and in this blog, we will create three views:
- Orders by Customer
- Orders by Employee
- General Orders
We will start with the Orders by Customer. To begin, add a TableSheet to the SpreadJS instance, and hide the new row and action column:
Now we can add a view to the table that we created earlier, utilizing the styles we made for the related data fields:
Finally, we can set that data view in the TableSheet:
Similar code can be used to create the orders by employee view, and we can use a simple view for the default orders:
That’s all you need to do to create multiple views from a Data Manager. To give this feature a try, make sure to download a trial of SpreadJS today. Take a look at our demos running live on our website.