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 (