Merge blocks can be filtered and sorted with linked instructions that help to shape the used data in each merge block. This article shows how to add sorting and filter instructions to existing merge blocks.

These instructions can be added using the out-of-the-box dialog boxes. Consider the following merge block:

Sorting Merge Blocks

Using the Dialog

A dialog box can be used to add filters and sorting instructions:

Sorting Merge Blocks

After a filter has been added using the dialog, only data rows with a LineTotal value larger than 1000 are visible:

Sorting Merge Blocks

Apply Instructions Programmatically

In order to apply these instructions programmatically, the MergeBlockInfo TX Text Control .NET Server for ASP.NET
DocumentServer.DataSources Namespace
MergeBlockInfo Class
The MergeBlockInfo class is used to insert a table or paragraph based repeating merge block into a TextControl instance using the DataSourceManager.InsertMergeBlock method.
class can be utilized. The following code uses the SubTextPart TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
SubTextPart Class
A SubTextPart object represents a user-defined part of a TX Text Control document.
at the current input position to create an instance of the MergeBlockInfo. After that, a new filter is added to the list of FilterInstructions TX Text Control .NET Server for ASP.NET
DocumentServer.DataSources Namespace
MergeBlockInfo Class
Filters Property
Gets or sets a list of filter instructions which are used to filter the data rows before merging.
. Additionally, a sorting instruction is added to the SortingInstructions TX Text Control .NET Server for ASP.NET
DocumentServer.DataSources Namespace
MergeBlockInfo Class
SortingInstructions Property
Gets or sets a list of sorting instructions which are used to sort the data rows before merging.
property.

// check if there is a SubTextPart at the
// current input position
if (textControl1.SubTextParts.GetItem() == null)
return;
// retrieve current SubTextPart
SubTextPart stpMergeBlock = textControl1.SubTextParts.GetItem();
// check if SubTextPart is a MergeBlock
if (TXTextControl.DocumentServer.DataSources.DataSourceManager.IsMergeBlock(
textControl1.SubTextParts.GetItem()) == true) {
// create a MergeBlockInfo object from SubTextPart
TXTextControl.DocumentServer.DataSources.MergeBlockInfo mbInfo =
new TXTextControl.DocumentServer.DataSources.MergeBlockInfo(stpMergeBlock);
// add a filter
mbInfo.Filters.Add(
new TXTextControl.DocumentServer.DataShaping.FilterInstruction(
"Price",
TXTextControl.DocumentServer.DataShaping.RelationalOperator.GreaterThan,
500));
mbInfo.SortingInstructions.Add(
new TXTextControl.DocumentServer.DataShaping.SortingInstruction(
"Price",
TXTextControl.DocumentServer.DataShaping.SortOrder.Ascending));
// important: apply the settings
mbInfo.Apply();
view raw test.cs hosted with ❤ by GitHub

At the end, it is very important to call the Apply TX Text Control .NET Server for ASP.NET
DocumentServer.DataSources Namespace
MergeBlockInfo Class
Apply Method
Stores the meta data (filters, sorting instructions and the block merging condition) in the SubTextPart which represents the block.
method that stores the meta data (filters, sorting instructions and the block merging condition) in the SubTextPart which represents the merge block.