mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-04-04 20:04:27 +00:00
fix #587
This commit is contained in:
@@ -24,6 +24,7 @@ const HeaderCell = (props) => {
|
||||
const {
|
||||
text,
|
||||
sort,
|
||||
sortCaret,
|
||||
filter,
|
||||
filterRenderer,
|
||||
headerTitle,
|
||||
@@ -69,7 +70,7 @@ const HeaderCell = (props) => {
|
||||
cellAttrs.className = cs(cellAttrs.className, 'sortable');
|
||||
|
||||
if (sorting) {
|
||||
sortSymbol = <SortCaret order={ sortOrder } />;
|
||||
sortSymbol = sortCaret ? sortCaret(sortOrder, column) : <SortCaret order={ sortOrder } />;
|
||||
|
||||
// append customized classes or style if table was sorting based on the current column.
|
||||
cellClasses = cs(
|
||||
@@ -86,7 +87,7 @@ const HeaderCell = (props) => {
|
||||
: headerSortingStyle
|
||||
};
|
||||
} else {
|
||||
sortSymbol = <SortSymbol />;
|
||||
sortSymbol = sortCaret ? sortCaret(undefined, column) : <SortSymbol />;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +152,7 @@ HeaderCell.propTypes = {
|
||||
onSort: PropTypes.func,
|
||||
sorting: PropTypes.bool,
|
||||
sortOrder: PropTypes.oneOf([Const.SORT_ASC, Const.SORT_DESC]),
|
||||
sortCaret: PropTypes.func,
|
||||
isLastSorting: PropTypes.bool,
|
||||
onFilter: PropTypes.func,
|
||||
onExternalFilter: PropTypes.func
|
||||
|
||||
@@ -403,6 +403,24 @@ describe('HeaderCell', () => {
|
||||
it('header should render SortSymbol as default', () => {
|
||||
expect(wrapper.find(SortSymbol).length).toBe(1);
|
||||
});
|
||||
|
||||
describe('when sortCaret is defined ', () => {
|
||||
beforeEach(() => {
|
||||
column = { ...column, sortCaret: jest.fn() };
|
||||
wrapper = shallow(
|
||||
<HeaderCell column={ column } index={ index } onSort={ onSortCallBack } />
|
||||
);
|
||||
});
|
||||
|
||||
it('header should not render SortSymbol', () => {
|
||||
expect(wrapper.find(SortSymbol).length).toBe(0);
|
||||
});
|
||||
|
||||
it('should call column.sortCaret correctly', () => {
|
||||
expect(column.sortCaret).toHaveBeenCalledTimes(1);
|
||||
expect(column.sortCaret).toHaveBeenCalledWith(undefined, column);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('and sorting prop is true', () => {
|
||||
@@ -420,6 +438,30 @@ describe('HeaderCell', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when sortCaret is defined ', () => {
|
||||
beforeEach(() => {
|
||||
column = { ...column, sortCaret: jest.fn() };
|
||||
wrapper = shallow(
|
||||
<HeaderCell
|
||||
column={ column }
|
||||
index={ index }
|
||||
onSort={ onSortCallBack }
|
||||
sortOrder={ Const.SORT_ASC }
|
||||
sorting
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
it('header should not render SortSymbol', () => {
|
||||
expect(wrapper.find(SortSymbol).length).toBe(0);
|
||||
});
|
||||
|
||||
it('should call column.sortCaret correctly', () => {
|
||||
expect(column.sortCaret).toHaveBeenCalledTimes(1);
|
||||
expect(column.sortCaret).toHaveBeenCalledWith(Const.SORT_ASC, column);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when headerSortingClasses is defined ', () => {
|
||||
const classes = 'foo';
|
||||
const order = Const.SORT_DESC;
|
||||
|
||||
Reference in New Issue
Block a user