Skip to content

Commit 9226685

Browse files
4manasamashm
andauthored
search filter issue fixed in ListView component (#360)
* search filter issue fixed in ListView component * fixed build issue --------- Co-authored-by: mashm <[email protected]>
1 parent b0c3736 commit 9226685

File tree

1 file changed

+16
-29
lines changed
  • packages/react-sdk-components/src/components/template/ListView

1 file changed

+16
-29
lines changed

packages/react-sdk-components/src/components/template/ListView/ListView.tsx

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ interface ListViewProps extends PConnProps {
6565
const SELECTION_MODE = { SINGLE: 'single', MULTI: 'multi' };
6666

6767
let myRows: any[];
68-
let myDisplayColumnList: any[];
6968

7069
let menuColumnId = '';
7170
let menuColumnType = '';
@@ -119,6 +118,7 @@ export default function ListView(props: ListViewProps) {
119118
const rowID = compositeKeys && compositeKeys?.length === 1 ? compositeKeys[0] : defRowID;
120119

121120
const [arRows, setRows] = useState<any[]>([]);
121+
const [rowsData, setRowsData] = useState<any[]>([]);
122122
const [arColumns, setColumns] = useState<any[]>([]);
123123
const [response, setResponse] = useState<any[]>([]);
124124

@@ -291,16 +291,6 @@ export default function ListView(props: ListViewProps) {
291291
});
292292
}
293293

294-
function getMyColumnList(arCols: any[]): string[] {
295-
const myColList: string[] = [];
296-
297-
arCols.forEach(col => {
298-
myColList.push(col.id);
299-
});
300-
301-
return myColList;
302-
}
303-
304294
/** Will return field from a filter expression */
305295
function getFieldFromFilter(filter, dateRange = false) {
306296
let fieldValue;
@@ -543,8 +533,8 @@ export default function ListView(props: ListViewProps) {
543533

544534
// store globally, so can be searched, filtered, etc.
545535
myRows = usingDataResults;
546-
myDisplayColumnList = getMyColumnList(myColumns);
547536

537+
setRowsData(myRows);
548538
// At this point, if we have data ready to render and haven't been asked
549539
// to NOT call setRows and setColumns, call them
550540
if (bCallSetRowsColumns) {
@@ -604,24 +594,22 @@ export default function ListView(props: ListViewProps) {
604594
}, [listContext]);
605595

606596
function searchFilter(value: string, rows: any[]) {
597+
const cols = arColumns.map(ele => {
598+
return ele.id;
599+
});
600+
607601
function filterArray(el: any): boolean {
608-
const bReturn = false;
609-
for (const key of Object.keys(el)) {
610-
// only search columsn that are displayed (pzInsKey and pxRefObjectClass are added and may or may not be displayed)
611-
if (myDisplayColumnList.includes(key)) {
612-
let myVal = el[key];
613-
if (myVal !== null) {
614-
if (typeof myVal !== 'string') {
615-
myVal = myVal.toString();
616-
}
617-
if (myVal.toLowerCase().indexOf(value.toLowerCase()) >= 0) {
618-
return true;
619-
}
602+
return Object.keys(el).some(key => {
603+
// only search columns that are displayed (pzInsKey and pxRefObjectClass are added and may or may not be displayed)
604+
if (cols.includes(key)) {
605+
const myVal = el[key];
606+
if (myVal !== null && typeof myVal !== 'undefined') {
607+
const strVal = String(myVal); // Ensure myVal is a string
608+
return strVal.toLowerCase().includes(value.toLowerCase());
620609
}
621610
}
622-
}
623-
624-
return bReturn;
611+
return false;
612+
});
625613
}
626614

627615
rows = rows.filter(filterArray);
@@ -631,8 +619,7 @@ export default function ListView(props: ListViewProps) {
631619

632620
function _onSearch(event: any) {
633621
const searchValue = event.target.value;
634-
635-
const filteredRows = searchFilter(searchValue, myRows.slice());
622+
const filteredRows = searchFilter(searchValue, rowsData?.slice());
636623

637624
setRows(filteredRows);
638625
}

0 commit comments

Comments
 (0)