mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
fix #26
This commit is contained in:
parent
b2bd0fc81a
commit
b00007cde9
@ -5,9 +5,10 @@ import _ from './utils';
|
||||
|
||||
|
||||
const HeaderCell = ({ column, index }) => {
|
||||
const { headerTitle, text, headerAlign } = column;
|
||||
const { headerTitle, text, headerAlign, headerFormatter } = column;
|
||||
const attrs = {};
|
||||
const headerStyle = {};
|
||||
const children = headerFormatter ? headerFormatter(column, index) : text;
|
||||
|
||||
if (headerTitle) {
|
||||
attrs.title = _.isFunction(headerTitle) ? headerTitle(column, index) : text;
|
||||
@ -19,9 +20,10 @@ const HeaderCell = ({ column, index }) => {
|
||||
|
||||
attrs.style = headerStyle;
|
||||
|
||||
|
||||
return (
|
||||
<th { ...attrs }>
|
||||
{ column.text }
|
||||
{ children }
|
||||
</th>
|
||||
);
|
||||
};
|
||||
@ -30,6 +32,7 @@ HeaderCell.propTypes = {
|
||||
column: PropTypes.shape({
|
||||
dataField: PropTypes.string.isRequired,
|
||||
text: PropTypes.string.isRequired,
|
||||
headerFormatter: PropTypes.func,
|
||||
formatter: PropTypes.func,
|
||||
formatExtraData: PropTypes.any,
|
||||
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
|
||||
@ -119,4 +119,32 @@ describe('HeaderCell', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when column.headerFormatter prop is defined', () => {
|
||||
const column = {
|
||||
dataField: 'id',
|
||||
text: 'ID'
|
||||
};
|
||||
const formatterResult = (<h3>{ column.text }</h3>);
|
||||
const formatter = sinon.stub()
|
||||
.withArgs(column, index)
|
||||
.returns(formatterResult);
|
||||
column.headerFormatter = formatter;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<HeaderCell column={ column } index={ index } />);
|
||||
});
|
||||
|
||||
afterEach(() => { formatter.reset(); });
|
||||
|
||||
it('should render successfully', () => {
|
||||
expect(wrapper.length).toBe(1);
|
||||
expect(wrapper.contains(formatterResult)).toBe(true);
|
||||
});
|
||||
|
||||
it('should call custom headerFormatter correctly', () => {
|
||||
expect(formatter.callCount).toBe(1);
|
||||
expect(formatter.calledWith(column, index)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user