Gathering detailed insights and metrics for react-select-table
Gathering detailed insights and metrics for react-select-table
Gathering detailed insights and metrics for react-select-table
Gathering detailed insights and metrics for react-select-table
@ag-grid-enterprise/rich-select
Advanced Data Grid / Data Table supporting Javascript / Typescript / React / Angular / Vue
react-table-drag-select
React component for drag selecting table cells
react-table-select
React table with selectable rows.
react-row-select-table
simple data table react Component
npm install react-select-table
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (87.94%)
SCSS (10.8%)
HTML (1.05%)
CSS (0.17%)
Shell (0.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
6 Stars
507 Commits
1 Forks
1 Watchers
9 Branches
1 Contributors
Updated on Nov 28, 2023
Latest Version
5.3.5
Package Id
react-select-table@5.3.5
Unpacked Size
735.62 kB
Size
162.66 kB
File Count
65
NPM Version
8.15.0
Node Version
16.17.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
2
A combination of item management (addition, deletion, sorting, etc.) using redux, and a table component to display them.
This version is a complete rewrite, treat it as a completely different library
1# Npm 2npm install react-select-table 3 4# Yarn 5yarn add react-select-table
On every section there is example code given, if you want to follow along building the example from an empty create-react-app, you'll also need these libraries:
1# Npm 2npm install @reduxjs/toolkit react-redux @fortawesome/fontawesome-svg-core @fortawesome/react-fontawesome @fortawesome/free-solid-svg-icons sass axios 3 4# Yarn 5yarn add @reduxjs/toolkit react-redux @fortawesome/fontawesome-svg-core @fortawesome/react-fontawesome @fortawesome/free-solid-svg-icons sass axios
In your index.js
, at the top:
1import 'react-select-table/dist/index.css';
For the example code, we'll be using sass
In your App.js
, at the top:
1import './App.scss';
In App.scss
:
1@use '~react-select-table/src/scss/style' as rst;
Each table reducer is identified by a unique string, which is called the namespace of the reducer. You will need it to dispatch actions for the reducer, to get state properties, and to pass it to the table component, so it's a good idea to define it once, and export it to avoid typos.
To create a table reducer use the createTable
function. It takes a namespace as the first argument,
and an object containing options as the second. You can see the default options as well as a description
of each option in optionsUtils.js, but we'll go through the most important ones here.
Each row to be added to the table must be an object (you can't add plain strings),
and as is the case for the reducer, it must also be identified by a unique string or number,
which is called the key of the row. The key can be the id of the item in the database,
or an auto-incrementing number or uuid if no database is involved. In any case, the key of the row should be
able to be derived from the row object, and that is the job of the keyBy
option.
If the key of a row is just a property inside the object, you can simply set the keyBy
option to
a string being the path to that property. In more complex cases you can set it to a function that takes
a row object as an argument and returns the key of the row.
Note that the key of the row is used internally as an object key,
meaning that the item key 1
is considered equal to '1'
, and that whenever you receive keys from the library
(ex. the selected keys on the onSelectionChange event handler), they are in string form regardless of the original type.
If a reducer isn't the root reducer, you must set the statePath
option to a string being the path to the reducer.
Say we're making a todo list, and our objects are of this format:
1interface Todo { 2 userId: number; 3 id: number; 4 title: string; 5 completed: boolean; 6}
We'll set keyBy='id'
, and searchProperty='title'
to enable searching by title.
We must also pick a namespace for the reducer, let's say todos
. Our completed store.js
code is:
1import { configureStore } from '@reduxjs/toolkit' 2import { createTable } from 'react-select-table' 3 4export const tableNamespace = 'todos' 5 6export default configureStore({ 7 reducer: createTable(tableNamespace, { 8 keyBy: 'id', 9 searchProperty: 'title' 10 }) 11})
In a typical app, where there other reducers as well, the code will look more like this:
1import { configureStore } from '@reduxjs/toolkit' 2import { createTable } from 'react-select-table' 3 4export const tableNamespace = 'todos' 5 6export default configureStore({ 7 reducer: { 8 todoTable: createTable(tableNamespace, { 9 keyBy: 'id', 10 searchProperty: 'title', 11 statePath: 'todoTable' 12 }), 13 ...otherReducers 14 } 15})
To complete the store setup, we need to add a store provider.
index.js
1import React from 'react'; 2import ReactDOM from 'react-dom/client'; 3import './index.css'; 4import App from './App'; 5import reportWebVitals from './reportWebVitals'; 6 7import { Provider } from 'react-redux' 8import store from './store' 9 10const root = ReactDOM.createRoot(document.getElementById('root')); 11root.render( 12 <React.StrictMode> 13 <Provider store={store}> 14 <App /> 15 </Provider> 16 </React.StrictMode> 17); 18 19// If you want to start measuring performance in your app, pass a function 20// to log results (for example: reportWebVitals(console.log)) 21// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 22reportWebVitals();
The component is exported as Table
, and you can see the available props in TableProps.js.
The first required prop is namespace
, which should be the same one that you gave to the reducer.
The second required prop is columns
, which should be an array of column objects.
You can see the properties of a column object also in TableProps.js.
To set the title of the column, use the title
property.
To specify how the content of the column is derived from a row object, you have three options:
path
of the column to a string being the path to that property.
If you stop here, the value of the row property will be displayed directly, but if you need more customization you
can set the render
of the column to a function that takes the value of the row property as an argument
and returns the content to be displayed. Note that setting the path
of the column, makes the column sortable.path
, the number of the row will be displayed in that column,
or passed to the render
function if provided.path
unset,
and use the second argument of the render
function which is the entire row object,
to derive and return the content.There is also a third argument passed to render
, which is an object with a className
property which you can set
to give a custom class to the cell.
Columns are also identified by a unique string, called the key of the column.
By default, if path
is set it is used as the key, but if it's not, or there are multiple columns with the same path
,
you must set the key
property of the column to a unique string.
You can set the isHeader
property of the column to true, to use th elements instead of td.
Finally, you can optionally set the defaultWidth
of the column to a number,
which is the percentage of the table width that should be taken up by the column on the initial render.
Continuing with the todo list example, we'll import the namespace from the store setup file.
We will then add our four columns:
Our code thus far is:
App.js
1import './App.scss' 2 3import React from 'react' 4import { Table } from 'react-select-table' 5import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' 6import { faCheck, faXmark } from '@fortawesome/free-solid-svg-icons' 7 8import { tableNamespace } from './store' 9 10const columns = [ 11 { 12 title: "A/I", 13 defaultWidth: 10 14 }, 15 { 16 title: "Id", 17 path: "id", 18 isHeader: true, 19 defaultWidth: 10 20 }, 21 { 22 title: "Title", 23 path: "title", 24 defaultWidth: 50 25 }, 26 { 27 title: "Completed", 28 path: "completed", 29 defaultWidth: 20, 30 render: (completed, todo, options) => { 31 options.className = completed ? "text-green" : "text-red" 32 return <FontAwesomeIcon icon={completed ? faCheck : faXmark}/> 33 } 34 } 35]; 36 37export default function App() { 38 return <div className="App"> 39 <Table columns={columns} namespace={tableNamespace} /> 40 </div> 41}
App.scss
1@use '~react-select-table/src/scss/style' as rst; 2 3.App { 4 height: 100vh; 5 box-sizing: border-box; 6 background-color: #f5f5f5; 7 padding: 1rem 2rem; 8} 9 10.text-red { 11 color: red; 12} 13 14.text-green { 15 color: green; 16} 17
The action creators, state selectors, and hooks, are all packaged together in an object called utils.
Each table reducer has its own utils package, which you can access with the getTableUtils
function.
This function takes the namespace of a reducer, and returns the utils for that reducer.
To dispatch an action outside a React component (ex. in middleware or a thunk action),
you can find the action creators in the actions
property of the utils object.
See Actions.js for the complete list of action creators and their descriptions.
To dispatch an action from inside a React component, there is the useActions
hook.
The hooks can be found in the hooks
property of the utils object.
The useActions
hook returns an object containing the action creators, but already wrapped in a dispatch call.
Of course, you can still manually dispatch the raw action creators if you prefer.
At this point, our table is pretty useless as it is empty, so we'll use axios to make an api request to get some dummy todo items and add them to our table, showcasing some action creators in the process.
To get access to the useActions
hooks, we need to import getTableUtils
, call it with the table namespace,
and destructure the hook
property from the returned object.
Then, in a useEffect hook, we use the startLoading
action to show a loading indicator,
and then make a request to get the todo items. If the request succeeds, we use the setItems
action to add them to
the table, and if it fails we use the setError
action to display an error message.
So our final App.js
code looks like this:
1import './App.scss' 2 3import React, { useEffect } from 'react' 4import { getTableUtils, Table } from 'react-select-table' 5import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' 6import { faCheck, faXmark } from '@fortawesome/free-solid-svg-icons' 7import axios from 'axios' 8 9import { tableNamespace } from './store' 10 11/* const columns = [ 12... 13]; */ 14 15const { hooks } = getTableUtils(tableNamespace) 16 17export default function App() { 18 const actions = hooks.useActions() 19 20 useEffect(() => { 21 actions.startLoading() 22 axios.get("https://jsonplaceholder.typicode.com/todos") 23 .then(response => actions.setItems(response.data)) 24 .catch(() => actions.setError("Something went wrong")) 25 }, [actions]) 26 27 return <div className="App"> 28 <Table columns={columns} namespace={tableNamespace} /> 29 </div> 30}
To learn more, you can read FullDemo.jsx. It's a continuation of this example todo list, but using all the library features.
Each table can take a custom className as a prop, and in such custom class you can set the values of predefined variables to customize the appearance, blissfully unaware of the element structure.
Every property that has to do with the appearance, is set to the value of a css variable. To find the name of the variable that controls the property that you want to customize, you can use inspect element.
For example, the variable that controls the color of selected rows, when the table is focused, is
--rst-row_selected_focused_background-color
, and you can set it to light blue using:
1.selection-blue { 2 --rst-row_selected_focused_background-color: lightblue; 3}
The naming convention for the css variables is element_state1_..._stateN_property
,
and if the variable with that name is not defined or set to unset
,
the properties that use that variable will fall back to the element_state1_..._state(N-1)_property
variable,
recursively until the element_property
variable.
For example, if you want to set the background color of the selected rows to light blue, regardless if the table is focused or not, you can do it with:
1.selection-blue { 2 --rst-row_selected_background-color: lightblue; 3 --rst-row_selected_focused_background-color: unset; 4}
To customize the default appearance, make sure that your stylesheet is imported after the library's,
and set the variables just like in the example above, but inside the rst-container
class.
There are 2 things than can only be customized using sass: Whether the even or the odd rows are striped,
and the prefix of the css variables (rst-
by default).
Another advantage is that you can use the shorthand form to customize a border (with css only you must set the width, style, and color, separately).
The simplest way to customize the appearance is with the load-config
mixin.
It takes a configuration map as an argument, and you can see all the keys
it can have in _variables.scss.
For example, the key that controls the border between the columns is column.border
,
and you can set it to 4px thick solid gray as such:
1.thick-border { 2 @include rst.load-config(( 3 "column.border": 4px solid gray 4 )) 5}
The naming convention for the configuration keys is element_state1_..._stateN.property
,
and if the key with that name is set to unset
, the value of the element_state1_..._state(N-1).property
key will be used instead, recursively until the element.property
key.
To customize the default appearance, you can pass a map like the one load-config
takes,
to the $config
variable, when importing the stylesheet.
For example, to set the default appearance to a dark-mode style, and set the stripe order to odd:
1@use '~react-select-table/src/scss/style' as rst with ( 2 $stripe-order: odd, 3 $config: ( 4 "head.background-color": #2c3034, 5 "head.border-color": white, 6 "head.color": white, 7 "root-container.background-color": #212529, 8 "body.color": white, 9 "pg-page.color": white, 10 "pg-page.border": 1px solid transparent, 11 "pg-page_current.background-color": transparent, 12 "pg-page_current.border-color": white 13 ) 14)
In a column object, you can set the key
property to a string.
Then you can use media queries to control the visibility of said column.
For example, say that your table has a className of table-responsive
,
then to hide the column with the key id
on screens smaller than 600px you can use:
1@media screen and (max-width: 600px) { 2 .table-responsive [data-col-key=id] { 3 width: 0 !important; 4 } 5}
I added multiple items to the table but only one is visible Check that you have set the 'keyBy' option correctly
I added the table component inside a flex column, and when I expand the table columns the flex column expands as well
Add min-width: 0
css rule to the flex column containing the table
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 0/18 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
40 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More