Skip to main content Skip to footer

Batch Updates in OdataCollectionView

Batch Updates

OData is an open protocol that allows the creation and consumption of queryable and interoperable RESTful APIs in a standard and straightforward way.

The ODataCollectionView class allows Wijmo applications to use OData data sources. It has always supported CRUD operations by committing changes (edits, adds, and deletes) immediately to the database. In the latest version, we added support for deferred batch updates.

To use this new feature, start by setting the deferCommits property to true. This will cause the ODataCollectionView to track any changes made to the data but will prevent any commits to the database until you call the commitChanges to commit the changes to the database or the cancelChanges method to discard the changes without committing them.

For example, the code below creates an ODataCollectionView with deferred commits, and handles two buttons that commit or cancel the changes:

// TripPinService (OData V4)  
 // [https://www.odata.org/blog/trippin-new-odata-v4-sample-service/](https://www.odata.org/blog/trippin-new-odata-v4-sample-service/)  
 // [https://services.odata.org/V4/TripPinServiceRW](https://services.odata.org/V4/TripPinServiceRW)  
 let url = '[https://services.odata.org/V4/(S(3vn0je…))/TripPinServiceRW/](https://services.odata.org/V4/(S(3vn0je%E2%80%A6))/TripPinServiceRW/)'  
 let view = new ODataCollectionView(url, 'Airlines', {  
     keys: ['AirlineCode'], // entity keys are required to write data  
     deferCommits: true  
 });  

 document.getElementById('btn-commit').addEventListener('click', (e) => {  
     let btn = e.target as HTMLInputElement;  
     btn.disabled = true;  
     view.commitChanges((xhr: XMLHttpRequest) => {  
         btn.disabled = false;  
     });  
 });  

 document.getElementById('btn-cancel').addEventListener('click', () => {  
     view.cancelChanges();  
 });
Read the full Wijmo 2020 v1 release.

If you have something interesting that you want to bring to our attention, we would love to hear it!

Chris Bannon - Global Product Manager

Chris Bannon

Global Product Manager of Wijmo
comments powered by Disqus