npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-bootstrap-table2-toolkit-react18-node20

v2.1.6

Published

The toolkit for react-bootstrap-table2

Downloads

45

Readme

react-bootstrap-table2-toolkit

react-bootstrap-table2 support some additional features in react-bootstrap-table2-toolkit.

In the future, this toolkit will support other feature like row delete, insert etc. Right now we only following features:

  • Table Search
  • Export CSV
  • Column Toggle

Live Demo For Table Search Live Demo For Export CSV Live Demo For Column Toggle

API&Props Definitation


Install

$ npm install react-bootstrap-table2-toolkit --save

Add CSS

// es5 
require('react-bootstrap-table2-toolkit/dist/react-bootstrap-table2-toolkit.min.css');

// es6
import 'react-bootstrap-table2-toolkit/dist/react-bootstrap-table2-toolkit.min.css';

Table Search

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

const { SearchBar } = Search;
//...

  <ToolkitProvider
    keyField="id"
    data={ products }
    columns={ columns }
    search
  >
    {
      props => (
        <div>
          <h3>Input something at below input field:</h3>
          <SearchBar { ...props.searchProps } />
          <hr />
          <BootstrapTable
            { ...props.baseProps }
          />
        </div>
      )
    }
  </ToolkitProvider>
  1. You have to enable the search functionality via search prop on ToolkitProvider.

  2. ToolkitProvider is a wrapper of react context, you are supposed to wrap the BootstrapTable and SearchBar as the child of ToolkitProvider

  3. You should render SearchBar with searchProps as well. The position of SearchBar is depends on you.

SearchBar Props

className - [string]

Custom the class on input element.

placeholder - [string]

Custom the placeholder on input element.

style - [object]

Custom the style on input element.

delay = [number]

milionsecond for debounce user input.

srText = [string]

Customize the screen reader text for the search input. (Default: "Search this table")

Search Options

defaultSearch - [string]

Accept a string that will be used for default searching when first time table render.

<ToolkitProvider
  keyField="id"
  data={ products }
  columns={ columns }
  search={ {
    defaultSearch: 'search something here'
  } }
>
  // ...
</ToolkitProvider>

onColumnMatch - [function]

Acccpt a function which will be called when table try to match every cells when search happening. This function accept an object like below example:

function onColumnMatch({
  searchText,
  value,
  column,
  row
}) {
  // implement your custom match logic on every cell value
}

<ToolkitProvider
  keyField="id"
  data={ products }
  columns={ columns }
  search={ {
    onColumnMatch
  } }
>
  // ...
</ToolkitProvider>

Notes: You have to return true when your match logic is positive and vice versa.

searchFormatted - [bool]

If you want to search on the formatted data, you are supposed to enable this props. react-bootstrap-table2 will check if you define the column.formatter when doing search.

<ToolkitProvider
  keyField="id"
  data={ products }
  columns={ columns }
  search={ {
    searchFormatted: true
  } }
>
  // ...
</ToolkitProvider>

afterSearch - [Function]

After search done, this callback function will be called with newest result.

<ToolkitProvider
  keyField="id"
  data={ products }
  columns={ columns }
  search={ {
    afterSearch: (newResult) => console.log(newResult)
  } }
>
  // ...
</ToolkitProvider>

Clear Search Button

We have a built-in clear search function which allow user clear search status via clicking button:

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

const { SearchBar, ClearSearchButton } = Search;

<ToolkitProvider
  keyField="id"
  data={ products }
  columns={ columns }
  search
>
  {
    props => (
      <div>
        <SearchBar { ...props.searchProps } />
        <ClearSearchButton { ...props.searchProps } />
        ....
      </div>
    )
  }
</ToolkitProvider>

Export CSV

There are two steps to enable the export CSV functionality:

  1. Give exportCSV prop as true on ToolkitProvider.
  2. Render ExportCSVButton with csvProps. The position of ExportCSVButton is depends on you.
import ToolkitProvider, { CSVExport } from 'react-bootstrap-table2-toolkit';

const { ExportCSVButton } = CSVExport;

<ToolkitProvider
  keyField="id"
  data={ products }
  columns={ columns }
  exportCSV
>
  {
    props => (
      <div>
        <ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
        <hr />
        <BootstrapTable { ...props.baseProps } />
      </div>
    )
  }
</ToolkitProvider>

Export CSV Options

fileName - [String]

Custom the csv file name.

separator - [String]

Custom the csv file separator.

ignoreHeader - [bool]

Default is false. Give true to avoid to attach the csv header.

ignoreFooter - [bool]

Default is true. Give false to attach the table footer if enabled.

noAutoBOM - [bool]

Default is true.

blobType - [string]

Default is text/plain;charset=utf-8. Change to update the blob type of the exported file.

exportAll - [bool]

Default is true. false will only export current data which display on table.

onlyExportSelection - [bool]

Default is false. true will only export the data which is selected.

onlyExportFiltered - [bool]

Default is false. true will only export the data which is filtered/searched.

When you configure this prop as true, you must turn off exportAll.


Column Toggle

Let's see how to render the column toggle in your react component:

import BootstrapTable from 'react-bootstrap-table-next';
import ToolkitProvider, { ColumnToggle } from 'react-bootstrap-table2-toolkit';

<ToolkitProvider
  keyField="id"
  data={ products }
  columns={ columns }
  columnToggle
>
  {
    props => (
      <div>
        <ToggleList { ...props.columnToggleProps } />
        <hr />
        <BootstrapTable
          { ...props.baseProps }
        />
      </div>
    )
  }
</ToolkitProvider>

columnToggleProps props have enough information to let you custom the toggle list: [demo](Live Demo For Export CSV)

If you want to have default visibility on specified column, you can just give true or false on column.hidden.