From 6d4a733a88dd9c1b9d1e49e5dbc54edd6f2acad5 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Fri, 6 Mar 2020 14:52:29 -0700 Subject: [PATCH] Fix row selection when used with global filter Fixes #1900 Closes #1937 --- src/plugin-hooks/useFilters.js | 16 +++++++--------- src/plugin-hooks/useGlobalFilter.js | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/plugin-hooks/useFilters.js b/src/plugin-hooks/useFilters.js index c52e8f0..2b25fdd 100755 --- a/src/plugin-hooks/useFilters.js +++ b/src/plugin-hooks/useFilters.js @@ -237,19 +237,17 @@ function useInstance(instance) { // We technically could do this recursively in the above loop, // but that would severely hinder the API for the user, since they // would be required to do that recursion in some scenarios - filteredRows = filteredRows.map(row => { + filteredRows.forEach(row => { filteredFlatRows.push(row) filteredRowsById[row.id] = row if (!row.subRows) { - return row - } - return { - ...row, - subRows: - row.subRows && row.subRows.length > 0 - ? filterRows(row.subRows, depth + 1) - : row.subRows, + return } + + row.subRows = + row.subRows && row.subRows.length > 0 + ? filterRows(row.subRows, depth + 1) + : row.subRows }) return filteredRows diff --git a/src/plugin-hooks/useGlobalFilter.js b/src/plugin-hooks/useGlobalFilter.js index 3aea902..52ba560 100644 --- a/src/plugin-hooks/useGlobalFilter.js +++ b/src/plugin-hooks/useGlobalFilter.js @@ -107,22 +107,23 @@ function useInstance(instance) { // Filters top level and nested rows const filterRows = filteredRows => { - return filterMethod( + filteredRows = filterMethod( filteredRows, allColumns.map(d => d.id), globalFilterValue - ).map(row => { + ) + + filteredRows.forEach(row => { filteredFlatRows.push(row) filteredRowsById[row.id] = row - return { - ...row, - subRows: - row.subRows && row.subRows.length - ? filterRows(row.subRows) - : row.subRows, - } + row.subRows = + row.subRows && row.subRows.length + ? filterRows(row.subRows) + : row.subRows }) + + return filteredRows } return [filterRows(rows), filteredFlatRows, filteredRowsById]