Products Technologies Demo Docs Blog Support Company

Adding Sorting and Filter Instructions to Existing MergeBlocks

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.

Adding Sorting and Filter Instructions to Existing MergeBlocks

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 class can be utilized. The following code uses the SubTextPart at the current input position to create an instance of the MergeBlockInfo. After that, a new filter is added to the list of FilterInstructions. Additionally, a sorting instruction is added to the SortingInstructions 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();

At the end, it is very important to call the Apply method that stores the meta data (filters, sorting instructions and the block merging condition) in the SubTextPart which represents the merge block.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.DocumentServer.DataShaping.FilterInstruction Class
  • TXTextControl.DocumentServer.DataShaping.SortingInstruction Class
  • TXTextControl.DocumentServer.DataSources.DataSourceManager Class
  • TXTextControl.DocumentServer.DataSources.MergeBlockInfo Class

Related Posts

ASP.NETWindows FormsWPF

MailMerge: Merging Hyperlinks using the FieldMerged Event

The MailMerge class is used to merge data into merge fields, image placeholders, barcodes and other reporting elements. With the help of the flexible FieldMerged event, additional elements can be…


ASP.NETWindows FormsWPF

Mail Merge MS Word Office Open XML (DOCX) Templates in C#

TX Text Control's MailMerge engine allows you to perform MS Word compatible mail merge processes in .NET based applications. This article gives an overview of the basic functionality and shows how…


ASP.NETWindows FormsWPF

MailMerge: Field Mapping and Handling of Unmerged Fields

Text Control's MailMerge API maps merge fields in templates with columns in supported data sources. This article explains the structure and how to handle unmerged fields.


ASP.NETWindows FormsWPF

MailMerge: Data Structures Explained with a Sample Template and JSON Data

The MailMerge class is used to merge JSON data into templates including merge fields and repeating merge blocks. This article gives an overview of the data structure based on a sample template…


ASP.NETWindows FormsWPF

X19 Sneak Peek: Manipulating MergeBlockInfo Objects

TX Text Control X19 provides the possibility to retrieve and manipulate information of an existing MailMerge merge block. This enables the editing of filters and sorting instructions programmatically.