Skip to content

Commit df369c8

Browse files
committed
fix issue in TableHeader, default showSortIcons to false
1 parent 47c180b commit df369c8

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/TableGenerator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export interface TableGeneratorProps {
185185
/**
186186
* Toggle to hide or show the arrow icons in the header cells when a column is sortable. Defaults true
187187
*/
188-
showSortIcons: boolean;
188+
showSortIcons?: boolean;
189189

190190
/**
191191
* Hide or show the header row. Defaults true
@@ -376,7 +376,7 @@ export const TableGenerator: React.FC<TableGeneratorProps> = (props) => {
376376
TableGenerator.defaultProps = {
377377
showHeader: true,
378378
showBody: true,
379-
showSortIcons: true,
379+
showSortIcons: false,
380380
striped: true,
381381
loading: false,
382382
enableNoDataMessage: true,

src/TableHeader.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {ReactNode} from "react";
22
import {ColumnOption, TableGeneratorProps} from "./TableGenerator";
33
import classNames from "classnames";
44
import {ISortStyle, SortOrder} from "./utils/sorting";
5+
import {CellContextDetails} from "./contextTypes";
56

67
export interface ITableHeaderProps extends Partial<TableGeneratorProps> {
78
sortConfiguration: ISortStyle;
@@ -39,7 +40,6 @@ const TableHeader: React.FC<ITableHeaderProps> = (props) => {
3940
return null;
4041
}
4142

42-
4343
// Determine if the column is sortable. First check if table sorting is true & this column is not disabled,
4444
// then if that doesn't evaluate true, just check if this column is set as sortable.
4545
const isSortable: boolean = (props.sortable && column.sortable !== false) || column.sortable;
@@ -48,23 +48,30 @@ const TableHeader: React.FC<ITableHeaderProps> = (props) => {
4848
// then if that doesn't evaluate true, just check if this column has them enabled.
4949
const showSortIcons: boolean = (props.showSortIcons && column.showSortIcons !== false) || column.showSortIcons;
5050

51-
5251
// Create the content to be rendered, starting with the headerValue.
53-
let content: ReactNode = column.headerValue;
52+
let content: any = column.headerValue;
53+
54+
// Construct this object with all the details needed for the value formatter / cell render functions
55+
const cellContextDetails: CellContextDetails = {
56+
value: content,
57+
row: undefined,
58+
key: column.key,
59+
data: props.data,
60+
column,
61+
index: undefined,
62+
};
5463

5564
// Reassign the content to the custom render function if it exists.
5665
if (column.headerRender) {
57-
content = column.headerRender(column.headerValue, undefined, column.key, props.data, column, i);
66+
content = column.headerRender(column.headerValue, cellContextDetails);
5867
}
5968

60-
6169
// Generate classes for the header cell.
6270
const thClasses: string = classNames(column.headerCellClassName, {
6371
"sortable-th": isSortable,
6472
"sortable-th-with-icons": isSortable && showSortIcons,
6573
});
6674

67-
6875
// Handle sorting, if enabled.
6976
function handleSort(): void {
7077
if (!isSortable) {

0 commit comments

Comments
 (0)