0

I am attempting to use react-bootstrap-typeahead as the search input for my react-data-table-component so that there would be an autosuggest option. My problem is on how could i reflect the selected option to my dataTable in such it would only show the specific item chosen (or paginate). Another problem is that I wasn't able to reflect the filteredItems as the option of the typeahead

const [filterText, setFilterText] = React.useState('');
  const [resetPaginationToggle, setResetPaginationToggle] = React.useState(
    false
  );

  //Data is passed to filtered items to sort
  const filteredItems =
    projects &&
    projects.filter(
      (project) =>
        project.name.toString().toLowerCase().includes(filterText) ||
        project?.description.toString().toLowerCase().includes(filterText)
    );

  const [singleSelections, setSingleSelections] = useState([]);
  const subHeaderComponentMemo = React.useMemo(() => {
    const handleClear = () => {
      if (filterText) {
        setResetPaginationToggle(!resetPaginationToggle);
        setFilterText('');
      }
    };

    let singleSelections = filterText;
    return (
      <Typeahead
        labelKey='name'
        onChange={(e) => setSingleSelections(e.target.value)}
        onClear={handleClear}
        options={filteredItems}
        placeholder='Search'
        selected={singleSelections}
      />
    );
  }, [filterText, resetPaginationToggle]);

This is my DataTable:

 <DataTable
          defaultSortAsc='id'
          pagination
          paginationResetDefaultPage={resetPaginationToggle}
          columns={columns}
          subHeader
          subHeaderComponent={subHeaderComponentMemo}
          persistTableHead
          expandableRows
          expandOnRowClicked
          expandableRowsComponent={<ExpandedComponent data={filteredItems} />}
          data={filteredItems}
        />
maria
  • 363
  • 2
  • 5
  • 14
  • It's pretty unclear what you're trying to do here and how the typeahead code relates to the datatable code. It sounds like you're trying to filter a set of options using the typeahead and pass those filtered options to the datatable for display, does that sound right? – ericgio Jul 10 '20 at 03:56
  • yes it is. i probably should have used the 'search' term instead of 'filter' – maria Jul 14 '20 at 14:00

0 Answers0