diff --git a/README.md b/README.md index 2777d0d..f788dfc 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ ## Sponsors +**React Table v7** is mostly planned and I (@tannerlinsley) am looking for Patreon support to make it a reality. It will require a decent time commitment on my part to not only implement it, but also help people migrate and continue to maintain it. If you would like to contribute to my Patreon goal for v7 and beyond, [visit my Patreon and help me out!](https://patreon.com/tannerlinsley). + @@ -159,9 +161,9 @@ $ npm install react-table ```javascript // ES6 -import ReactTable from "react-table"; +import ReactTable from 'react-table' // ES5 -var ReactTable = require("react-table").default; +var ReactTable = require('react-table').default ``` 3. Import styles by including `react-table.css` @@ -187,7 +189,7 @@ import 'react-table/react-table.css' ``` @@ -447,13 +449,13 @@ These are all of the available props (and their default values) for the main ` Progress ), - accessor: "progress", + accessor: 'progress', Cell: row => (
66 - ? "#85cc00" + ? '#85cc00' : row.value > 33 - ? "#ffbf00" - : "#ff2e00", - borderRadius: "2px", - transition: "all .2s ease-out" + ? '#ffbf00' + : '#ff2e00', + borderRadius: '2px', + transition: 'all .2s ease-out' }} />
) } -]; +] ``` ## Styles @@ -749,11 +751,11 @@ This makes it extremely easy to add, say... a row click callback! getTdProps={(state, rowInfo, column, instance) => { return { onClick: (e, handleOriginal) => { - console.log("A Td Element was clicked!"); - console.log("it produced this event:", e); - console.log("It was in this column:", column); - console.log("It was in this row:", rowInfo); - console.log("It was in this table instance:", instance); + console.log('A Td Element was clicked!') + console.log('it produced this event:', e) + console.log('It was in this column:', column) + console.log('It was in this row:', rowInfo) + console.log('It was in this table instance:', instance) // IMPORTANT! React-Table uses onClick internally to trigger // events like expanding SubComponents and pivots. @@ -761,10 +763,10 @@ This makes it extremely easy to add, say... a row click callback! // If you want to fire the original onClick handler, call the // 'handleOriginal' function. if (handleOriginal) { - handleOriginal(); + handleOriginal() } } - }; + } }} /> ``` @@ -777,9 +779,9 @@ You can use these callbacks for dynamic styling as well! getTrProps={(state, rowInfo, column) => { return { style: { - background: rowInfo.row.age > 20 ? "green" : "red" + background: rowInfo.row.age > 20 ? 'green' : 'red' } - }; + } }} /> ``` @@ -806,12 +808,12 @@ const columns = [ getProps: (state, rowInfo, column) => { return { style: { - background: rowInfo.row.name === "Santa Clause" ? "red" : null + background: rowInfo.row.name === 'Santa Clause' ? 'red' : null } - }; + } } } -]; +] ``` ## Pivoting and Aggregation @@ -832,20 +834,20 @@ Naturally when grouping rows together, you may want to aggregate the rows inside // In this example, we use lodash to sum and average the values, but you can use whatever you want to aggregate. const columns = [ { - Header: "Age", - accessor: "age", + Header: 'Age', + accessor: 'age', aggregate: (values, rows) => _.round(_.mean(values)), Aggregated: row => { // You can even render the cell differently if it's an aggregated cell - return row.value (avg); + return row.value (avg) } }, { - Header: "Visits", - accessor: "visits", + Header: 'Visits', + accessor: 'visits', aggregate: (values, rows) => _.sum(values) } -]; +] ``` Pivoted columns can be sorted just like regular columns including holding down the `` button to multi-sort. @@ -866,7 +868,7 @@ By adding a `SubComponent` props, you can easily add an expansion level to all r even have access to the row-level data if you need! Spark-charts, drill-throughs, infographics... the possibilities are endless!
- ); + ) }} /> ``` @@ -982,21 +984,21 @@ Accessing internal state and wrapping with more UI: return (
           
-            state.allVisibleColumns ==={" "}
+            state.allVisibleColumns ==={' '}
             {JSON.stringify(state.allVisibleColumns, null, 4)}
           
         
{makeTable()}
- ); + ) }} ``` @@ -1034,21 +1036,21 @@ Supply a function that implements the native javascript [`Array.sort`](https://d ```javascript defaultSortMethod = (a, b, desc) => { // force null and undefined to the bottom - a = a === null || a === undefined ? -Infinity : a; - b = b === null || b === undefined ? -Infinity : b; + a = a === null || a === undefined ? -Infinity : a + b = b === null || b === undefined ? -Infinity : b // force any string values to lowercase - a = typeof a === "string" ? a.toLowerCase() : a; - b = typeof b === "string" ? b.toLowerCase() : b; + a = typeof a === 'string' ? a.toLowerCase() : a + b = typeof b === 'string' ? b.toLowerCase() : b // Return either 1 or -1 to indicate a sort priority if (a > b) { - return 1; + return 1 } if (a < b) { - return -1; + return -1 } // returning 0 or undefined will use any subsequent column sorting methods or the row index as a tiebreaker - return 0; -}; + return 0 +} ``` ## Filtering