Initializing help system before first use

VDL Set Sorting

As of VDL 4.7, all Set entities have default sorting applied when the data is loaded into a view. The sorting is based on the Set data type (Integer, String, Boolean) and the values are sorted by default in ascending order. Both of these settings can be configured, allowing you to apply different sorting per Set entity specify and change the sort direction to descending.
The <vdl-set-sorter set="" comparator="" direction=""> component is used to manage any custom Set sorting. When adding a vdl-set-sorter, you can specify either:
  • a built-in comparator (see the VDL Reference for possible values).
  • an expression that return a JavaScript array of ordered values.
  • a function reference
You can also specify the sort direction as asc (ascending) or desc (descending).
There are built-in comparators that can be used to sort sets of strings.
  • The built-in Boolean comparator can cope with Sets of type Boolean, Integer, or String, and will try to cast the value into a Boolean. For example:
    • true values could be t, True, 1, true.
    • false values could be f, False, 0, false.
  • The built-in comparator days can be used to sort strings representing short or long names of days of the week in English, for example Mon, Tuesday.
  • The built-in comparator months can be used to sort strings representing short or long names of months in English, for example Jan, December.

Example using a built-in comparator with a Set of strings

<vdl-set-sorter set="MonthsOfYear" comparator="months">

Example using a JavaScript array of ordered values to sort a Set of strings:

<vdl-set-sorter set="AlertLevels" comparator="=['Low', 'Medium', 'High', 'Critical']" direction="desc">
The comparator function should follow the standard JavaScript CompareFunction interface, for more see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort. This is a function that takes in two values, a and b, and returns one of the following:
  • less than 0 if a has a lower sorting value.
  • 0 if a and b have equal sorting value.
  • greater than 1 if a has a greater sorting value.

Example applying a custom comparator expression on a Set of strings

This sort the value A04 to the beginning of the data, and sort the rest of the values in alphabetical order:

<vdl-set-sorter set="AGENCY" comparator="=a === 'A04' ? -1 : b === 'A04' ? 1 : a.localeCompare(b)">

As a function reference:

<script>
function sortAgencySet(a, b) {
    return a === 'A04' ? -1 : b === 'A04' ? 1 : a.localeCompare(b);
}
</script>
<vdl-set-sorter set="AGENCY" comparator="=sortAgencySet">

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.