1.3.2 • Published 2 years ago

react-dynamic-bs-table v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-dynamic-bs-table

Dynamic reusable table component, with pagination feature, image support, custom classes and live search bar, for React, using Bootstrap default styling.

The purpose of this package is to propose a dynamic table React component, in fact, simply add table header labels and data to display as props, the component will take care to display all data whatever is the number of array's keys. It also support images.

It is possible to enable or disable the pagination and the search bar, by specifying it in props, number of items per page to display, custom table classes, and more...

NPM NPM JavaScript Style Guide JavaScript Style Guide JavaScript Style Guide NPM

Features

Install

npm install --save react-dynamic-bs-table

Usage

import React, { Component } from 'react'

import CustomTable from 'react-dynamic-bs-table'
import 'react-dynamic-bs-table/dist/index.css'

const headList = [
  "Brand", "Model", "Country", 'Picture'
]

const dataToDisplay = [
  { brandName: "Ford", modelName: "Fusion", country: "USA", imagePath: "https://..." },
  { brandName: "Seat", modelName: "Ibiza", country: "Spain", imagePath: "https://..." },
  { brandName: "Volkswagen", modelName: "Golf", country: "Germany", imagePath: "https://..." },
  { brandName: "Renault", modelName: "Clio", country: "France", imagePath: "https://..." },
  { brandName: "Peugeot", modelName: "308", country: "France", imagePath: "https://..." },
  { brandName: "Chevrolet", modelName: "Cruze", country: "USA", imagePath: "https://..." },
  { brandName: "Renault", modelName: "Kangoo", country: "France", imagePath: "https://..." },
  { brandName: "Volkswagen", modelName: "Polo", country: "Germany", imagePath: "https://..." },
  { brandName: "Audi", modelName: "A3", country: "Germany", imagePath: "https://..." },
  { brandName: "Seat", modelName: "Ateca", country: "Spain", imagePath: "https://..." },
  { brandName: "BMW", modelName: "M4", country: "Germany", imagePath: "https://..." },
  { brandName: "Mercedes", modelName: "Class A 180", country: "Germany", imagePath: "https://..." },
  { brandName: "Ford", modelName: "Fiesta", country: "USA", imagePath: "https://..." },
]

class Example extends Component {
  render() {
    return (
            <CustomTable
              bodyList={dataToDisplay}
              headList={headLabels}
              imageHeight={75}
              rowNumber
              enablePagination
              itemsPerPage={5}
              tableHover
              //this is just an example, you have to specify the class names
              //of your css library you are using (bootsrap, material...)
              customClass={{
                tableClass:"table table-hover",
                trClass:"text-center",
              }}
              enableSearchBar
              />
          )
  }
}

Live Search Bar

You can enable a live multiple keys search bar. It is used to filter the data through all the keys of the array you provide in bodyList prop.

The search bar use default Bootstrap styling, but you can custom it by providing your own classes in searchBarClass prop.

Example

...

class Example extends Component {
  ...
  render() {
    return (
            <CustomTable
              ...
              enableSearchBar
              searchBarClass="form-control my_other_class"
              searchBarPlaceholder="Find something..."
              />
          )
  }
}

Properties

PropsTypeDefaultRequiredDescription
bodyList2D arrayN/AYesThis is the data you want to display, usually it's data you fetch from database
headList1D arrayN/AYesLabels to display in table head
imageHeightIntegernullNoSet the image height if in your data there is images to display (absolute image path)
imageWidthIntegernullNoSet the image width if in your data there is images to display (absolute image path)
rowNumberBooleanfalseNoIf set to true an extra column will be added to the table to display row number
enablePaginationBooleanfalseNoIf set to true the pagination will be enabled
itemsPerPageInteger10NoNumber of items to be shown per page on the table
tableHoverBooleanfalseNoThis applies table-hover bootstrap class
tableBkColorStringN/ANoThis applies a background color to the table. Available values (info, danger, warning, success)
tableBorderedBooleanfalseNoThis applies table-bordered bootstrap class
tableStripedBooleanfalseNoThis applies table-striped bootstrap class
tableResponsiveBooleanfalseNoThis applies table-responsive bootstrap class
tableInverseBooleanfalseNoThis applies table-inverse bootstrap class
customClassObjectN/DNoThis applies the classes you provide in this prop. customClass is an object that expects three keys, tableClass, trClass and theadClass, wich values are simply strings that refer to the class names of the css library you are using, example value: {{tableClass:"table table-hover",trClass:"text-center p-0",theadClass:"text-primary"}}
enableSearchBarBooleanfalseNoWhen set to true a live search bar will be shown on top of the table
searchBarPlaceholderStringSearch for...NoPlaceholder of the live search bar
searchBarClassStringN/DNoCustom class you want to apply for the search bar. You can use your own classes ou some other CSS libraries you use

Live Example

See live example here!

Changelog

1.3.2

  • Updated Live Example URL

1.3.1

  • README.md updated

1.3.0

  • Added a live search bar feature
  • Added enableSearchBar, searchBarPlaceholder, searchBarClass props for the live search bar
  • Some code improvement
  • README.md updated

1.2.0:

  • Added theadClass property for customClass prop

1.1.0:

  • Added customClass prop
  • Added PropTypes
  • Changed named export for the component to default export
  • Some corrections to README.md
  • Added typing definitions for the package

1.0.1:

  • Update README.md

1.0.0:

  • First Release of my first library in history

License

MIT © parazitenew

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago