I am trying to render the background color on certain columns a certain color, in my react-data-grid (adazzle).
The problem is that I am getting this white padding around my cells :
How do I get rid of this white padding?
I simply followed the way the formatter was used in this example :
http://adazzle.github.io/react-data-grid/examples.html#/custom-formatters
My ColumnFormatter looks like this :
const ColumnFormatter = React.createClass({
propTypes: {
value: React.PropTypes.number.isRequired
},
render() {
return (
<div style={{background: '#f2f9de'}}>
{this.props.value}
</div>);
}
});
And I set up my columns like this :
this._columns.push({
key: i,
name: "blah " + i,
sortable: true,
resizable: true,
formatter: ColumnFormatter
})
The class ag-row-hover and ag-column-hover are added to cells as the mouse is dragged over the cells row or column. The example below demonstrates the following: CSS class ag-row-hover has background color added to it, so when you hover over a cell, the row will be highlighted.
To enable filtering in the Grid, set the allowFiltering to true. Filtering options can be configured through filterSettings . To use filter, inject the Filter module in the grid. To learn about how to work with Filtering Options, you can check on this video for React Grid.
You can add CSS styles to each row in the following ways: rowStyle : Property to set style for all rows. Set to an object of key (style names) and values (style values). getRowStyle : Callback to set style for each row individually.
In the formatter you can give the background as you are giving right now but you can add a css like this in your custom css file:
#parentDivOfGrid div.react-grid-Row div.react-grid-Cell {
padding-left: 0px ;
padding-right: 0px;
line-height: 2.1;
text-align: center;
}
But your React data grid should be inside a div like this:
<div id="parentDivOfGrid">
<ReactDataGrid
...
/>
</div>
You might want to play around with the line height value in css according to your grid.
this is a simple way but may not work exactly how you want...
somefile.js
<div id="someTableId">
<ReactDataGrid
...
/>
</div>
somefile.css...
#someTableId div.react-grid-Row div.react-grid-Cell:nth-of-type(1),
#someTableId div.react-grid-Row div.react-grid-Cell:nth-of-type(2){
background-color: #f2f9de;
}
also, i like to make things simple when i do a react-data-grid cell formatter (note: with the css way above you don't need the formatter but just to show how i simplify formatters or if you do it another way with a formatter)...
this._columns.push({
key: i,
name: "blah " + i,
sortable: true,
resizable: true,
formatter: (props)=>(<div style={{background: '#f2f9de'}}>{props.value}</div>;
})
and actually i would have done a className instead of style and used a css file but that just what i prefer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With