From 7b4d915ff852fe8c1d886ce76db8137d1e973076 Mon Sep 17 00:00:00 2001 From: alnasir7 Date: Sat, 27 Feb 2021 17:11:48 -0500 Subject: [PATCH] default search columns --- frontend/components/ModelForm.tsx | 15 ++++++++------- frontend/components/common/Table.tsx | 10 ++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/frontend/components/ModelForm.tsx b/frontend/components/ModelForm.tsx index d458c5cf4..b93e24902 100644 --- a/frontend/components/ModelForm.tsx +++ b/frontend/components/ModelForm.tsx @@ -148,7 +148,6 @@ export const ModelTable = ({ })), [tableFields], ) - tableFields = tableFields.map((column, index) => { if (column.converter) { const renderFunction = column.converter @@ -167,12 +166,12 @@ export const ModelTable = ({ tableFields.push({ name: 'Actions', - render: (_, index) => ( + render: (id) => (
{allowEditing && ( )} - {actions && actions(objects[index])} + {actions && actions(objects[id])}
), }) @@ -211,7 +210,9 @@ export const ModelTable = ({ item.id ? item : { ...item, id: index }, )} columns={tableFields} - searchableColumns={searchableColumns || []} + searchableColumns={ + searchableColumns || tableFields.map((field) => field.name) + } filterOptions={filterOptions || []} /> diff --git a/frontend/components/common/Table.tsx b/frontend/components/common/Table.tsx index f73fa3ba2..dc31b7767 100644 --- a/frontend/components/common/Table.tsx +++ b/frontend/components/common/Table.tsx @@ -116,10 +116,12 @@ const Table = ({ return true } return searchableColumns.some((searchId) => { - const strings = item[searchId].split(' ') - return strings.some((string) => - string.toLowerCase().startsWith(searchQuery.toLowerCase()), - ) + if (typeof item[searchId] === 'string') { + const strings = item[searchId].split(' ') + return strings.some((string) => + string.toLowerCase().startsWith(searchQuery.toLowerCase()), + ) + } else return false }) }) const filteredData = searchedData.filter((item) => {