From aeadeeb85a8f4264d1f0f6455f9a79c3419f7e6c Mon Sep 17 00:00:00 2001 From: Emily Toy Date: Wed, 13 Jul 2022 14:16:21 -0400 Subject: [PATCH 1/2] Fix primefaces#2514: If sortField is specified, determine and set columnSortable and columnSortFunction refs when processing data. Otherwise, the refs are false and undefined, which results in the sortFunction not being run initially. --- components/lib/datatable/DataTable.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/lib/datatable/DataTable.js b/components/lib/datatable/DataTable.js index 9370bcfdac..9a3b9085fc 100644 --- a/components/lib/datatable/DataTable.js +++ b/components/lib/datatable/DataTable.js @@ -1236,6 +1236,13 @@ export const DataTable = React.forwardRef((props, ref) => { const sortField = (localState && localState.sortField) || getSortField(); const sortOrder = (localState && localState.sortOrder) || getSortOrder(); const multiSortMeta = (localState && localState.multiSortMeta) || getMultiSortMeta(); + var columns = getColumns(); + var sortColumn = columns.find((col) => col.props.field === sortField); + + if (sortColumn) { + columnSortable.current = sortColumn.props.sortable; + columnSortFunction.current = sortColumn.props.sortFunction; + } if (ObjectUtils.isNotEmpty(filters) || props.globalFilter) { data = filterLocal(data, filters); From 58c4a892c5c4ac060705eb3fca81f212fe7b1bb8 Mon Sep 17 00:00:00 2001 From: Emily Toy Date: Wed, 13 Jul 2022 15:51:13 -0400 Subject: [PATCH 2/2] Update var to const. --- components/lib/datatable/DataTable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/lib/datatable/DataTable.js b/components/lib/datatable/DataTable.js index 9a3b9085fc..21f5d2c290 100644 --- a/components/lib/datatable/DataTable.js +++ b/components/lib/datatable/DataTable.js @@ -1236,8 +1236,8 @@ export const DataTable = React.forwardRef((props, ref) => { const sortField = (localState && localState.sortField) || getSortField(); const sortOrder = (localState && localState.sortOrder) || getSortOrder(); const multiSortMeta = (localState && localState.multiSortMeta) || getMultiSortMeta(); - var columns = getColumns(); - var sortColumn = columns.find((col) => col.props.field === sortField); + const columns = getColumns(); + const sortColumn = columns.find((col) => col.props.field === sortField); if (sortColumn) { columnSortable.current = sortColumn.props.sortable;