LabelFormatter

Agenty LabelFormatter is a way to style a field values into colorful labels, this function can be used in existing field as well a new label field can be added. There are 2 ways to use this function, to add style the field value into a colored label in the result table : 

  1. Without parameters
  2. With parameter

In this tutorial, we are going to try both of these options to see how the LabelFormatter function works :

Before

The scraping agent consider all the fields DataType as TEXT by default, so If you see the screenshot below, the ProductPrice field values is all in plain text format :

LabelFormatter Function Example-before

Without parameters

  1. Edit the scraping agent by clicking on the "Edit" tab and go to "Fields and Collections" section
  2. Go to the ProductPrice field and click on the "Edit" button to edit this field
  3. Now, click on the "Add Formatter" button as in screenshot below
    Capture 1
  4. The below modal dialog box will appear, where we need to select the LabelFormatter in drop-down and then leave the parameter as blank(by-default)
    Capture
  5. Save the function and the scraping agent configuration
  6. Go back to result tab (Remember : There are no need to re-run the agent to apply the changes we made in formatter, because the field formatter function just display the text in different styles and doesn't make any change in actual result data)
    LabelFormatter Function Example-after
  7. So, when we use the LabelFormatter function and don't pass any parameter, the function just convert that field values into label.

With parameter

By using the color parameter, we can change the color of our label :

  1. Just enter any valid color  name or hexadecimal color code in color parameter as in screenshot below.
    Capture
  2. Save the function and the scraping agent configuration
  3. Go back to result tab (Remember : There are no need to re-run the agent to apply the changes we made in formatter, because the formatter function just display the text in different styles and doesn't make any change in actual result data)
    LabelFormatter Function Example-after
  4. So, when we use the LabelFormatter function with color parameter, the function will style the field value with label with defined color in parameter