1.0.26 • Published 3 months ago

moonshield-table v1.0.26

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

Moonshield-Table

Created by Moonshield for the HRnet project - January 2024

This component has been created to replace a jQuery library used in the previous version of the HRnet application. It can however be used in any React application, as it adapts to the data it's given.

Installing Moonshield-Table

To use moonshield-table, you can use npm in your project with the following command :

npm install moonshield-table

Dependencies

NameVersion
Node18.14.2
React18.2.0

Usage

Once the library is installed in your React application, create a component and import Custom Table :

import { CustomTable } from 'moonshield-table';

Then, declare the columns your table will require in an array of objects. Each column requires a label (the name that will be displayed in your table), an accessor (same as the label, in snake_case or camelCase), and two booleans : sortable and searchable. Your array of objects should look like this :

  const columns = [
    {label: 'First Name', accessor: 'firstname', sortable: true, searchable: true},
    {label: 'Last Name', accessor: 'lastname', sortable: true, searchable: true},
    {label: 'Start date', accessor: 'startday', sortable: true, searchable: true},
    {label: 'Department', accessor: 'department', sortable: false, searchable: false},
    {label: 'Birthday', accessor: 'birthday', sortable: false, searchable: true},
  ];

Finally, you can use the custom table in your component. It will always take 100% of the width of its container, so you can easily adapt the size of its container. You can enable or disable the search feature by changing the value of the boolean.

The data has to be provided in json format, with fields matching the accessors of the columns.

  return (
    <div className='your-table-container'>
      <CustomTable columns={columns} searchFeature={true} data={tableData} />
    </div>
  );

Features

  • Sort the columns : the columns having the sortable boolean to true will have the sort option active, which allows them to be ascendingly sorted on the first click on the header of the column, and descendingly sorted on second click of the column.
  • Search : if the searchFeature of the CustomTable is set to true, a search input will be displayed and will search the data of the columns having the searchable boolean to true.
  • Pages : this component is meant to display a lot of data, which is why a pages feature is implemented. You can select the amount of data that will be displayed per page thanks to the select on top of the table.
  • Responsive : the component is responsive and can be displayed on desktops and mobile screens without cropping, assuming there isn't an abusive amount of columns (up to 10).

License

This package is released under the MIT license. You are free to use, modify and distribute this software, as long as the copyright is left intact.

1.0.26

3 months ago

1.0.25

3 months ago

1.0.24

3 months ago

1.0.19

4 months ago

1.0.18

4 months ago

1.0.22

4 months ago

1.0.21

4 months ago

1.0.20

4 months ago

1.0.23

4 months ago

1.0.17

4 months ago

1.0.16

4 months ago

1.0.15

4 months ago

1.0.14

4 months ago

1.0.13

4 months ago

1.0.11

4 months ago

1.0.10

4 months ago

1.0.12

4 months ago

1.0.9

4 months ago

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago