2.0.3 • Published 12 months ago

react-sortable-customizable-table v2.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

Sortable and customizable REACT Table v2.0.3

This React module allows you to create a data table with column headers that support ascending/descending sorting. The table is configurable, with customization options for column headers and colors. You can easily integrate it into your project and adjust the styles to meet your needs.

Installation

npm react-sortable-customizable-table

Usage

import React, { useState } from 'react';
import ReactSortableTable from 'react-sortable-customizable-table';

export default function ParentComponent() {

    const [sortColumn, setSortColumn] = useState('');
    const [sortDirection, setSortDirection] = useState('asc');
    const data = [
        { id: 1, name: 'John Doe', position: 'Developer', startDate: '2022-01-01' },
        // other data...
    ];
    const columns = [
        { accessor: 'name', label: 'Name' },
        { accessor: 'position', label: 'Position' },
        { accessor: 'startDate', label: 'Start Date' },
        // other columns...
    ];
        //... your code

    return (
    <>
      //... your code
    
    <ReactSortableTable
        tableData={data}
        columns={columns}
        headerBgColor="#335123"
        headerTextColor="white"
        headerHoverBgColor="#444"
        headerHoverTextColor="yellow"
        headerActiveBgColor="blue"
        headerActiveTextColor="white"
        evenRowBgColor="blue"
        oddRowBgColor="yellow"
        hoverRowBgColor="#f2f2f2"
        bodyTextColor="pink"
        sortable={true} // set true or false for enable / disable sorting
        dateFormat="MM/dd/yyyy" // Customize date format
      />
        //... your code
    </>
    )
}

Props

Prop NameTypeRequiredDescription
tableDataarrayYesThe data to display in the table.
columnsarrayYesThe columns of the table with accessor and label.
headerBgColorstringNoBackground color of the column headers.
headerHoverBgColorstringNoBackground color of the column headers on hover.
headerTextColorstringNoText color of the column headers.
headerHoverTextColorstringNoText color of the column headers on hover.
headerActiveBgColorstringNoBackground color of the active sorted column header.
headerActiveTextColorstringNoText color of the active sorted column header.
evenRowBgColorstringNoBackground color of even rows.
oddRowBgColorstringNoBackground color of odd rows.
hoverRowBgColorstringNoBackground color of rows on hover.
bodyTextColorstringNoText color of the table cells.
sortableboolNoWhether the columns are sortable. Defaults to true.
dateFormatstringNoFormat to display dates in. Options include 'yyyy-MM-dd', 'MM/dd/yyyy', 'dd/MM/yyyy'. Defaults to 'yyyy-MM-dd'.

Default style and customization

the default colors are :

  • headerBgColor: #fff (white)
  • headerTextColor: #000 (black)
  • headerHoverBgColor: #f0f0f0 (light gray)
  • headerHoverTextColor: #333 (dark gray)
  • headerActiveBgColor: #ccc (light gray)
  • headerActiveTextColor: #000 (black)
  • evenRowBgColor: #f9f9f9 (light gray)
  • oddRowBgColor: #bdc3c7 (light gray)
  • hoverRowBgColor: #eaeaea (light gray)
  • bodyTextColor: #000 (black)

You can customize the table's style using the props, as shown in this (horrible) usage example:

<ReactSortableTable
  tableData={data}
  columns={columns}
  headerBgColor="#335123"
  headerTextColor="white"
  headerHoverBgColor="#444"
  headerHoverTextColor="yellow"
  headerActiveBgColor="blue"
  headerActiveTextColor="white"
  evenRowBgColor="#f2f2f2"
  oddRowBgColor="#fff"
  hoverRowBgColor="#e0e0e0"
  bodyTextColor="black"
  sortable={false} // Set to true, or omit this prop to enable sorting
/>

Custom SVG Icons

The component library includes custom SVG icons that can be used within your React components. This icons can be easily customized.

Icons Props

  • className (string, optional): CSS class for custom styling. Default are : 'upIcon', 'downIcon', and upDownIcon.
  • width (number, optional): Width of the icon. Default is 64.
  • height (number, optional): Height of the icon. Default is 64.
  • fillColor (string, optional): Color of the icon. Accepts any CSS color value. Default is 'currentColor'

Customization

You can customize the icon's appearance by changing the width, height, and fillColor props. For example, setting fillColor="red" will color the icon red, while width={20} and height={20} will resize the icon to 20x20 pixels.

Note

All icons in the library are SVG-based, which means they are scalable and can be styled with CSS. This ensures that they look sharp on all screen sizes and resolutions.

Licence

This project is licensed under the MIT License. See the LICENSE file for more details.

2.0.3

12 months ago

2.0.2

12 months ago

2.0.1

12 months ago

2.0.0

12 months ago

1.0.0

12 months ago