react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

Search is not working

Open cb29960 opened this issue 5 years ago • 5 comments

I started working with react-bootstrap-table-next this morning and everything went really well until i got to the search. The search box appears but does not filter any records. This is what i have installed: react-bootstrap-table-next 4.0.3", react-bootstrap-table2-paginator 2.1.2", react-bootstrap-table2-toolkit 2.1.3",

Here's my code:

import BootstrapTable from 'react-bootstrap-table-next';
import 'react-bootstrap-table-next/dist/react-bootstrap-table2.min.css';
import paginationFactory from 'react-bootstrap-table2-paginator';
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';

actionFormat(cell, row, rowIndex) {
        return (<div><span className='fa fa-pencil-square-o' onClick={() => this.props.parentEdit(cell, row, rowIndex)} data-id={cell} title='Edit'></span>
            <span className='fa fa-trash-o' data-id={cell} onClick={() => this.props.parentDelete(cell, row, rowIndex)} title='Delete'></span></div>)
}
render() {        
        const { SearchBar } = Search;        
        return (
                <Container fluid>
                    <ToolkitProvider
                        keyField="Id"
                        data={this.state.data}
                        columns={this.props.columns}
                        search
                        bootstrap4
                    >
                        {
                            props => (
                                <div>
                                    Search:
                                    <SearchBar {...props.searchProps} />
                                    <BootstrapTable bootstrap4 data={this.state.data} columns={this.props.columns} keyField='Id'
                                        pagination={paginationFactory()} striped condensed>
                                    </BootstrapTable>
                                </div>
                            )
                        }
                    </ToolkitProvider>
        );
    }

Any idea why the search is not executing?

cb29960 avatar Aug 27 '20 18:08 cb29960

@cb29960 I believe you need to change your properties assignment on your <BootstrapTable> component to be something like this: <BootstrapTable bootstrap4 pagination={paginationFactory()} striped condensed {...props.baseProps} />

Essentially, you want the ToolkitProvider to be providing the data, columns, and keyField properties. As written in your original post, you're setting those properties again on the BootstrapTable instance directly.

See this page for the relevant docs.

cwilso03 avatar Sep 01 '20 00:09 cwilso03

Yes, this worked! Thank you very much!

cb29960 avatar Sep 15 '20 13:09 cb29960

above answer is absolutely fine for asked question but in my case search is only worked when I typed something in input field before that the does not shows any data. I want entire data to display without any search also. I have implemented same code as @cb29960. any help will be appreciated. Thank you...

Devmobilesutra avatar May 18 '21 04:05 Devmobilesutra

above answer is absolutely fine for asked question but in my case search is only worked when I typed something in input field before that the does not shows any data. I want entire data to display without any search also. I have implemented same code as @cb29960. any help will be appreciated. Thank you...

I'm not sure I follow... Regardless, probably best to open a new issue, since it sounds like you are experiencing a different problem.

cwilso03 avatar May 18 '21 11:05 cwilso03

import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit/dist/react-bootstrap-table2-toolkit';

polixisNG avatar Feb 21 '22 14:02 polixisNG