From 85b5ff99ca57c567c7b7474de486edb14c3a2392 Mon Sep 17 00:00:00 2001 From: Melloware Date: Mon, 28 Nov 2022 09:00:48 -0500 Subject: [PATCH] Fix #3712: PrimeReact.nullSortOrder working properly (#3713) --- components/lib/utils/ObjectUtils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/lib/utils/ObjectUtils.js b/components/lib/utils/ObjectUtils.js index 0e1c36ea1c..9a5a3aab52 100644 --- a/components/lib/utils/ObjectUtils.js +++ b/components/lib/utils/ObjectUtils.js @@ -224,16 +224,20 @@ export default class ObjectUtils { static sort(value1, value2, order = 1, locale, nullSortOrder = 1) { const result = ObjectUtils.compare(value1, value2, locale, order); + let finalSortOrder = order; + // nullSortOrder == 1 means Excel like sort nulls at bottom - const finalSortOrder = nullSortOrder === 1 ? order : nullSortOrder; + if (ObjectUtils.isEmpty(value1) || ObjectUtils.isEmpty(value2)) { + finalSortOrder = nullSortOrder === 1 ? order : nullSortOrder; + } return finalSortOrder * result; } static compare(value1, value2, locale, order = 1) { let result = -1; - const emptyValue1 = this.isEmpty(value1); - const emptyValue2 = this.isEmpty(value2); + const emptyValue1 = ObjectUtils.isEmpty(value1); + const emptyValue2 = ObjectUtils.isEmpty(value2); if (emptyValue1 && emptyValue2) result = 0; else if (emptyValue1) result = order;