Integration Toolkit Solutions Wiki

Simple orderBy() example

Reorder the given source data by key.

Source data

Paste this into a custom property, unsorted.

[
	{"fruit": "apples",  "count": 10},
	{"fruit": "bananas", "count": 8},
	{"fruit": "citrus",  "count": 11},
	{"fruit": "dates",   "count": 7}
]
Expression binding

Create this binding on another custom property. e.g., sorted.

orderBy(
	{this.custom.unsorted},
	it()['count']
)
Result
[
  {"fruit": "dates",   "count": 7},
  {"fruit": "bananas", "count": 8},
  {"fruit": "apples",  "count": 10},
  {"fruit": "citrus",  "count": 11}
]

descending() example

Expression binding
orderBy(
	{this.custom.unsorted},
	descending(
		it()['count']
	)
)
Result
[
  {"fruit": "citrus",  "count": 11},
  {"fruit": "apples",  "count": 10},
  {"fruit": "bananas", "count": 8},
  {"fruit": "dates",   "count": 7}
]

naturalOrder() example

Case-insensitive sort.

Expression binding
orderBy(
	{this.custom.unsorted},
	naturalOrder(
		it()['code']
	)
)
Source data
[
  {"fruit": "apples",  "code": "a10"},
  {"fruit": "bananas", "code": "8b"},
  {"fruit": "citrus",  "code": "A10"},
  {"fruit": "dates",   "code": 7}
]
Result
[
  {"code": 7,     "fruit": "dates"},
  {"code": "8b",  "fruit": "bananas"},
  {"code": "a10", "fruit": "apples"},
  {"code": "A10", "fruit": "citrus"}
]

Note that a10 is output before A10.

naturalCasedOrder() example

Case-sensitive sort.

Expression binding
orderBy(
	{this.custom.unsorted},
	naturalCasedOrder(
		it()['code']
	)
)
Result
[
  {"code": 7,     "fruit": "dates"},
  {"code": "8b",  "fruit": "bananas"},
  {"code": "A10", "fruit": "citrus"}.
  {"code": "a10", "fruit": "apples"}
]

Note that A10 is output before a10.


Functions used
  • orderBy() reorders the given source data per the given key expressions.
  • it() retrieves the loop value for an iterator from inside the nested expression.
  • descending() reverses the comparison order of any comparable handed to it.
  • naturalOrder()
  • naturalCasedOrder() orders in case-sensitive alphanumeric.
3 Likes