Intersoft WebGrid Documentation
Data editing with new Batch Update mode
See Also Send comments on this topic.
Intersoft WebGrid > WebGrid Features Overview > Editing Data > Data editing with new Batch Update mode

Glossary Item Box

WebGrid 7 features SmartBatchUpdate, a new major innovation that takes editing experience to a new level. This new technology enables your end user to make multiple changes to the data in the client side, while at the same time maintaining the changes as they navigate the data around.
Embracing elegant pending changes architecture, WebGrid submits all changes to server-side in a single request - making data update fast and efficient.  Please see SmartBatchUpdate overview to learn the fundamental concept of this new feature.
WebGrid 7's batch update also supports advanced data transaction operations such as cascading inserts, hierarchical tables, automatic object updates, identity insert handling and more. The user interface has also been improved to provide users with intuitive way to review and manage the changes. Learn more about user interface improvements such as call out notification, changes status and more.
The new technologies in WebGrid 7 are also designed to work in concert with each other, making it the most advanced data visualization and management component for dynamic, Web 2.0-enabled application.
Learn how to combine client binding and batch update along with inline editing to deliver powerful, "cloud"-ready and offline-capable Web application.

This topic contains the following sections:

 

Introducing SmartBatchUpdate

SmartBatchUpdate is a new feature in WebGrid 7 which enables you to perform multiple edits across multiple tables in real-time without postback/callback. All pending changes will be submitted into server at once with a single AJAX callback, thus eliminates waiting time and improves data editing experience in overall.

When WebGrid is operating in batch update editing mode, you can make multiple edits - such as adding new row, editing row, and deleting row - in real-time without server contact. You can also make multiple edits across hierarchical child tables which are linked through valid referential integrity in the same consistent fashion.

SmartBatchUpdate also supports more advanced scenarios such as cascading inserts and deletes on hierarchical tables. This allows you to conveniently add new master record and its child records in a row - making data entry across hierarchical tables a snap. Furthermore, WebGrid stores the relation between each new record and intelligently perform new identity translation and mapping it to related child records during physical database updates - freeing developers from tedious and lengthy codes.

SmartBatchUpdate provides numerous benefits for developers and end users, such as:

 

Pending Changes Concept

SmartBatchUpdate employs pending changes concept to provide solid functionality and architecture for its batch update features. With the concept, every row that has changed since its first load will result in a pending change.

A record row can contain only one pending change at a time, which is one of four modes below:

Each row's pending change is stored based on its corresponding table. This means that each table contains one or more pending changes which are associated with each logical row. As a result, SmartBatchUpdate provides solid and consistent object models and interfaces which enable pending changes to be consumed in multiple tables (hierarchical) configuration. For more information about batch update support for Hierarchical feature, please read Hierarchical Tables Support.

The following illustration describes the pending changes concept in a hierarchical Grid.


 
 
Pending changes are stored locally on client-side and can be accessed programmatically through client-side API

Furthermore, pending changes are automatically restored and synchronized with the current view whenever the Grid performed a FlyPostBack action - such as sorting, filtering, grouping, etc - or page full postback. This provides users with greater experience to interacting with information while maintaining current changes simultaneously.

SmartBatchUpdate also includes built-in pending changes management, such as ability to undo changes, accept changes, as well as review changes. For more information about pending changes management, please see Built-in Changes Management.

It's important to note that WebGrid requires your tables to have at least one unique key field, which is assigned to DataKeyField property of each WebGridTable instance. Multiple key fields scenario is also supported.

When Accept Changes command is invoked by users, WebGrid submits all pending changes to server in a single FlyPostBack (AJAX) callback. Upon receiving batch update request, WebGrid will automatically apply all pending changes to the data source in batch. Depending on your data source type, WebGrid will decide whether it should automatically apply the changes to physical database. To learn more about physical database updates, please visit Updating to Physical Database.

With solid and extensible pending changes architecture provided by SmartBatchUpdate, WebGrid 7 delivers reliable client-side editing solution for your Web application, where data lost is not an option.

 

Rich User Interface

In addition to solid editing architecture and powerful runtime features, SmartBatchUpdate also provides your end-users with rich visual elements to easily determine added, modified and deleted rows.

The following image shows a WebGrid in hierarchical tables with several pending changes.

Figure 1. WebGrid provides rich visual hints and indicators for pending changes.

 

SmartBatchUpdate includes additional visual elements and indicators, such as explained below:

 

Streamlined Editing Process

SmartBatchUpdate incorporates streamlined editing behaviors to make it even easier, faster and more convenient for users to work with data.

When the batch update feature is enabled, the following behaviors will be automatically enabled:

In addition to the editing behaviors enhancement, SmartBatchUpdate also enhances the user experience in overall. To learn more, please see automatic changes preservation and compatibility with existing features.

 

Built-in Changes Management

SmartBatchUpdate provides a high-level built-in changes management, in addition to the solid underlying infrastructure which maintains the integrity and consistency of pending changes and batch update process.

Changes management in WebGrid 7 includes the following features:

Review Changes dialog box provides easy-access to all pending changes across tables and views - makes it easy for users to undo several records or accept changes.


Note that the changes will be preserved even though the view has changed completely eg, through sorting or paging. To learn more, see Automatic Changes Preservation mode.

 

Hierarchical Tables Support

SmartBatchUpdate includes full support for hierarchical tables configuration, makes it the most advanced and reliable solution for enterprise-class data editing requirements.

Consider a WebGrid with Customers-Order-Order Details configuration. Ideally, end user will need the ability to perform changes in child table in the same way and manner as they do it in root table.

WebGrid Enterprise 7's unique SmartBatchUpdate technology simply makes it happen. The following image shows a hierarchical WebGrid with several changes on each table. The pending changes can be easily recognized by its visual style and row header's indicator.

When batch update feature is enabled in WebGrid, it will be automatically applied globally to include all child tables.

The batch update feature is supported in hierarchical WebGrid, regardless of the datasource type. That means no matter what your WebGrid is bound to - either it is a DataSet object, a hierarchical custom object, or an ISDataSource object - the batch update will always work in the same way and consistent fashion.

The batch update includes specific support for hierarchical WebGrid such as:

 

Automatic Changes Preservation

As in the good tradition of WebGrid, SmartBatchUpdate is rigorously designed for the best user experiences. In simpler words, the batch update feature shouldn't limit end user to perform common data operations - especially the one that completely changes the current view.

For quick instances - data sorting, grouping or filtering are normally disabled when batch update feature is used. Some common reasons are that the changes are either too difficult to be maintained, or impossible to be preserved between view change.

SmartBatchUpdate takes data editing to a new height by allowing users to do what they used to do - column sorting, filtering, grouping, and even data paging - while simultaneously maintain the existing pending changes that they have made.

WebGrid does not only maintain the existing pending changes when you work on different views of your data, it perfectly restores the visual styles and row state of your pending changes as in where it left off.

Automatic changes preservation, an integral feature of SmartBatchUpdate - enables many scenarios not possible to achieve in the past - dramatically enhances user productivity. For instance, it is possible to edit a record in page 1, then jump to page 3 and edit more records, then go back to page 1 and edit more fields on existing edited record.

Automatic changes preservation works on data operations that change the view completely, such as:

This feature is enabled by default when batch update feature is enabled. There are no additional steps required by developers to activate this feature.

 

Updating to Physical Database

SmartBatchUpdate provides sophisticated implementation to automate the batch updating process to the physical database.

The automatic updating feature significantly reduces development time - as you are not required to write any codes to perform the batch update, or very minimal efforts when you need to customize the updating process in more advanced scenarios.

To understand the physical updating concept better, please see the following illustration.

Understanding Batch Update Processes

As shown in the illustration above, the physical update has several processes such as detailed in the following:

Various Datasource Support

WebGrid 7 supports physical database updates in various scenarios, such as when bound to different type of datasource, hierarchical tables configuration, and more. The following list describes the supported scenarios in more details:

New Identity Insert

One of the best practices in database design concept is to have at least one unique, auto-increment field in each table which acts as the row's identifier.

When you insert a new row to the table, the database will issue a new, unique identity value of the new inserted row. However, each database provider has different ways to retrieve the new identity's value. As such, Microsoft .NET Framework doesn't include built-in implementation to retrieve identity insert in its ADO.NET technology.

SmartBatchUpdate relies heavily on row's identifier to differentiate each record in order to work properly. Therefore, developers should make sure that the new identity's value is correctly retrieved and passed to WebGrid during batch update processing.


The following list describes the techniques to retrieve the new identity's value in various data source type:

 

Localization

The new batch update feature in WebGrid 7 introduces a dozens of new User Interface elements, which contains many new textual settings as well.

As in good tradition of WebGrid, all textual settings are customizable according to the culture specified by developer. Each textual setting can also be overridden individually. You can find the complete text settings in default.xml which is located in the Localization folder.

The following table lists the new text settings that you can customize.

Category Text Setting Key Default Text Setting Value (English)
CommonText PendingChanges {0} pending change(s).
DeletedRowNoEdit Row marked as deleted cannot be modified.
DeletedRowNoExpand Row marked as deleted cannot be expanded.
BatchUpdateSuccess All changes have been successfully updated to server.
BatchUpdateSuccessWithPartialErrors One or more changes are not updated due to server errors.
MessageBoxText UnsavedPendingChanges You have made one or more changes on WebGrid records. Any unsaved changes will lose.
NotifyPendingChanges There are {0} unsaved pending changes. Click Accept Changes button below to save changes.
UndoPendingChanges Are you sure you want to undo all pending changes?
UndoSelectedPendingChanges Are you sure you want to undo selected pending changes?
DeletedRowEditException You cannot make changes to the row which parent has been marked as deleted.
DuplicateKeyException The pending changes already contain a record with key '{0}'
PrimaryKeyEditException Modification on primary key's field of pending changes is not allowed.
BatchUpdateException An exception has occurred while processing batch update. please correct or undo your changes. \n\Exception details:\n{0}
BatchUpdatePartialException WebGrid failed to update {0} out of {1} changes due to errors. Please review and correct your changes. \n\nThe following records were not updated:\n{2}
Tooltip ModifiedRowState Modified row
AddedRowState Added row
DeletedRowState Deleted row
PendingChangesEmpty There are no pending changes
PendingChangesExisted There are {0} pending changes: {1} insert(s), {2} edit(s), {3} delete(s)
ReviewChanges Review Pending Changes
UndoChanges Undo All Changes
AcceptChanges Accept All Changes
ContextMenu/Row UndoSelection Undo Selection
DeleteSelection Delete Selection

 

Note: You may find empty text entries when using languages other than English. If you found empty entries on the language and culture that you are familiar with, please help us to translate the entries using the default.xml as the template and send it to feedback@intersoftpt.com.

 

Compatibility with Other Features

As in every major release of WebGrid, every new feature and enhancement are designed to work in conjunction with existing features. There are, though, some conditions and scenarios where the enhancements are not applicable, such as due to behavior conflicts.

In addition to comprehensive hierarchical tables and client side editing support, SmartBatchUpdate is also designed to work with existing features. Some of noteworthy key features are such as listed in the following:

Multiple Selection feature is also enhanced to work in harmony with batch update feature. When you select multiple rows that contain pending changes, the Undo Selection command will appear in context menu, allowing end user to quickly undo multiple pending changes. Also, when deletion feature is enabled and multiple rows are selected, Delete Selection will appear in the context menu.

All client side APIs and object models continue to work and function normally as published in the documentation.

There are no unknown compatibilities with specific features that could cause errors or misbehaviors when batch update is enabled as far as the time of this writing.

 

Client-side Programmability

SmartBatchUpdates is a set of comprehensive object models and application programming interfaces (API), serving as the main foundation and architecture for the pending changes concept introduced in WebGrid 7.

All pending changes operation that invoked from WebGrid's user interface is also using the same set of APIs and interfaces. The result is a powerful and highly extensible client side batch editing architecture, which enables developers to further extend the functionality to address their complex business requirements.

The following sections describe the new classes, methods and client side events that introduced as core programming interfaces for the batch update feature.

New classes

WebGridBatchUpdateSettings
This class contains all settings and behaviors related to batch update feature.

Properties:

 

WebGridCellData
This class holds the delta information of modified cell data.

Properties:

 

WebGridRowChanges
This class represents the changes for a row object.

Properties:

Methods:

New methods

Several methods have been added as extensions to provide batch update functionality. These methods will only be available when batch update feature is used.

 

Class New Method Parameters
WebGrid GetChangesCount ( Returns the count of all pending changes regardless of the state and table) -
UpdatePendingChangesStatus (Synchronize pending changes with Grid's user interface elements) -
UndoallChanges (Undo all pending changes regardless of the state and table) -
AcceptAllChanges (Accept all pending changes and submit them to server for batch update) -
GetChanges (Returns a list of WebGridRowChange objects) rowState (Specifies the state of the changes to get)
InvalidateChanges (Invalidate all pending changes to be reprocessed in the next synchronization) -
ClearChanges (Clear and remove all pending changes regardless of the state and table) -
WebGridTable GetChanges (Return a list of pending changes that existed in this table) rowState (Specifies the state of the changes to get)
GetChangesCount (Returns the count of the pending changes in this table) -
UndoChanges (Undo all pending changes in this table) -
InvalidateChanges (Invalidate all pending changes in this table) -
WebGridRow GetChanges (Returns the changes made to this row) rowState (Specifies the state of the changes to get)
GetRowState (Returns the state of this row. It will returns Unmodified if this row has no changes) -
InvalidateRowState (Invalidate the state of this row to be processed in the next synchronization) -
UndoChanges (Undo changes made to this row) skipUpdateStatus (Specifies whether to skip the status updating after undo)
AddPendingChanges (Mark changes made to this row and add it into pending changes collection) isProgrammatic (Specifies whether the method is called by user code)
SetDeleted (Mark this row as deleted) -
WebGridCell SetChanges (Change the text and value of this cell) text (The new text to be set)
value (The new value to be set. This parameter is optional, and only useful for valuelist column)

New client side events

The following table describes the new client side events related to batch update feature. 

Event Name Description Parameters
OnUndoChanges Fired when a row changes is about to be undo'ed controlId, rowObject (The row to be undo'ed)
OnUndoAllChanges Fired when undo all changes command is performed. controlId
OnAcceptAllChanges Fired when accept all changes command is performed controlId
OnAddPendingChanges Fired when a pending changes is about to be added controlId, table (The table on which pending changes is added to), rowChange (The tow change object)
OnRemovePendingChanges Fired when a pending changes is about to be removed controlId, table (The table on which pending changes is added to), rowChange (The row change object)
OnBatchUpdateSuccess Fired when batch update operation has been successfully completed controlId, hasPartialErrors (Whether the batch update contains one or more errors), partialErrorsXml (The xml document contains partial errors data)

 

Server-side Programmability

As in client-side, the same set of new classes and methods have also been added to server-side. This enables reliable synchronization between client-side and server-side, which results in consistent interfaces and elegant objects design.

For shared set of the new classes, methods and properties; please refer to Data editing with new Batch Update mode section above.

The following list shows additional methods to perform server-side related tasks.

  • GetChanges()
    Returns all pending changes regardless of the row's state and table.

  • GetChanges(RowState rowState)
    Returns all pending changes with given row state.

  • PerformBatchUpdate(bool throwExceptionOnError)
    Processes changes and updates it to physical database programmatically.

  • GetBatchUpdateExceptions()
    Returns one or more exceptions that occurred while processing batch update.

  • AddBatchUpdateException(WebGridBatchUpdateException exception)
    Adds an exception when a batch update-related error occurred. Use this method to take advantage of partial error support in custom object updating scenario.

  • OnBatchUpdate. Provided BatchUpdateEventArgs as the event argument.
    This event will always be invoked when batch update feature is enabled. This event is required to be handled for traditional and custom object binding. You can cancel WebGrid for further processing by setting false to its ReturnValue.

 

  • GetChanges(RowState rowState)
    Returns all pending changes in this table, given the row state.

  • UpdateRowIdentity(string dataMember, object originalValue, object processedValue)
    Updates and maps new identity of successive row inserts to intermediate objects in the data source. This method is required for traditional and custom object binding.

The provided server side APIs, as described above, enables you to programmatically work against pending changes data that submitted from client-side.

Several scenarios that can be achieved by using the provided APIs:

C# Copy Code
private void MapChangesToObject(List data, CustomObjects.Customer customer)
{    
   foreach (WebGridCellData cellData in data)    
   {        
      string newText = cellData.NewText;        
      switch (cellData.Column.DataMember)        
      {            
         case "CustomerID":                
            customer.CustomerID = newText;                
            break;            
         case "Address":                
            customer.Address = newText; 
            break;
...          
      }    
   }
}

Codes Explanation:

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.