# Change DataSource Dynamically

## Content

TableSheet provides the ability to inject the corresponding data from the data source in real-time without refreshing the webpage. <span style="color: rgb(23, 43, 77); font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: -0.07px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">This feature, for example, helps you to switch the data sources to a backup server in case the live server returns a connection error and many other scenarios.</span>
To update the data source dynamically, follow the steps below:

1. Invoke the **fromJSON** method.

    ```JavaScript
    spread.fromJSON(spreadJson);
    ```
2. Update the table datasource option by wrapping the datasource as an object in **Promise**’s **resolve** method.

    ```JavaScript
    let myTable = spread.dataManager().tables["myTable"];
    myTable.options = { 
       remote: {               
           read: function () { 
               return Promise.resolve(dataSource); 
                   } 
             } 
    };
    ```
3. Invoke the table’s **fetch** method with the new reload argument. This step refreshes the datasource and calls the **setDataView** method with an updated data source.

    ```JavaScript
    myTable.fetch(true).then(function()
    {
        let myView = myTable.views["myView"];
        let sheet = spread.getActiveSheetTab();
        sheet.setDataView(myView);
    });
    ```

> **Note**: View’s fetch method and Table’s fetch method have the same new reload argument. Hence, the setDataView method helps in clearing the cache status after fetching the data view again.