Articles in this section
Category / Section

How to increase the performance by using Batch Update in SfDataGrid in UWP ?

4 mins read

What is batch update?

Batch update is used to suspend the data operations like Sorting, Grouping, Filtering and Summary calculation, while modifying data (add, remove and property change). You can also use Batch updates to do bulk operations in SfDataGrid like sorting multiple column in single refresh, with optimized performance.

Data operations in SfDataGrid are suspended by calling SfDataGrid.View.BeginInit() method. After completing the bulk operations in SfDataGrid, you can refresh the View by calling SfDataGrid.View.EndInit(). Then data operations are resumed.

C:\Users\Giftline\Desktop\img.jpgNote: Use batch update only when you are doing bulk updates with Grid, or data operations like Sorting and Grouping in SfDataGrid. When you use batch update for single item refresh, then the performance will decreases.

Examples:

Sorting two columns by using Batch Update

When sorting the multiple columns in a single refresh in SfDataGrid, the performance decreases. So, you can use the Batch Update to increase the performance of the SfDataGrid. Before performing the SortColumnDescriptions for two columns, you can call the SfDataGrid.View.BeginInit(), and after performing SortColumnDescriptions for two columns, you can call SfDataGrid.View.EndInit() for refreshing the SfDataGrid.

The following code example explains how to use the SfDataGrid.View.BeginInit() and SfDataGrid.View.EndInit() methods.

C#

this.sfdatagrid.View.BeginInit();
this.sfdatagrid.SortColumnDescriptions.Add(new SortColumnDescription() { ColumnName = "CustomerName", SortDirection = System.ComponentModel.ListSortDirection.Descending });
this.sfdatagrid.SortColumnDescriptions.Add(new SortColumnDescription() { ColumnName = "CustomerId", SortDirection = System.ComponentModel.ListSortDirection.Descending });
this.sfdatagrid.View.EndInit();

 

Real-time updates using Batch Update

When you do Real-time updates in SfDataGrid with huge amount of data, the performance decreases. So, you can use the Batch Update to increase the performance of the SfDataGrid. Before performing the Real-time update operation, you can call SfDataGrid.View.BeginInit() and after performing the Real-time update operation, you can call SfDataGrid.View.EndInit() for refreshing the SfDataGrid.

The following code example explains how to use the SfDataGrid.View.BeginInit() and SfDataGrid.View.EndInit() methods.

C#

var sfdataGrid = sfDataGrid as SfDataGrid;
var vm = sfdataGrid.DataContext as ViewModel;
sfdataGrid.View.BeginInit();
//Do your RealTime Updates here
vm.ItemSource.NumberOfChanges = 0;
Random rand = new Random();
DateTime start = DateTime.Now;
foreach (var item in vm.ItemSource)
{
    if (vm.IsChecked)
    {
        item.EmployeeStatus = false;
        item.EmployeeSalary += rand.Next();
        item.EmployeeGender = "Female" + rand.Next();
        item.EmployeeArea = "Yahoo" + rand.Next();
        item.EmployeeAge += 1;
    }
    else
    {
        item.EmployeeStatus = true;
        item.EmployeeSalary += rand.Next();
        item.EmployeeGender = "Male" + rand.Next();
        item.EmployeeArea = "Google" + rand.Next();
        item.EmployeeAge += 1;
    }
}
sfdataGrid.View.EndInit();

 

Sample Links:

WPF

WRT

SilverLight

UWP


Conclusion

I hope you enjoyed learning about how toncrease the performance by using Batch Update in SfDataGrid in UWP

You can refer to our UWP SfDataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our UWP SfDataGrid  example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied