Skip to content

Commit 432ee4f

Browse files
committed
fix new on sort
1 parent 4fa7aa6 commit 432ee4f

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frame-one-table",
3-
"version": "0.3.8",
3+
"version": "0.3.9",
44
"description": "A react table with maximum flexibility.",
55
"main": "build/index.js",
66
"module": "build/index.es.js",

src/TableGenerator.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ export interface ColumnOption<T = any> {
9292
*/
9393
headerValue?: any;
9494

95+
/**
96+
* Implement custom sorting for your smart table column
97+
*/
98+
onSort?: () => void;
99+
95100
/**
96101
* Format function to run the values for the column's body cells through before displaying them (ie. (height) => height + "cm"). Does not modify the value used to compare for sorting the column
97102
*/
@@ -162,11 +167,6 @@ export interface TableGeneratorProps {
162167
*/
163168
paginatorProps: IPaginatorProps;
164169

165-
/**
166-
* Implement custom sorting for your smart table
167-
*/
168-
onSort?: () => void;
169-
170170
/**
171171
* Hide or show the header row. Defaults true
172172
*/
@@ -286,7 +286,6 @@ export const TableGenerator: React.FC<TableGeneratorProps> = (props) => {
286286
columnOptions={props.columnOptions}
287287
headerClassName={props.headerClassName}
288288
headerStyle={props.headerStyle}
289-
onSort={props.onSort}
290289
/>
291290
)}
292291

src/TableHeader.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {ColumnOption, TableGeneratorProps} from "./TableGenerator";
33
import {CellContextDetails} from "./contextTypes";
44

55
export interface ITableHeaderProps extends Partial<TableGeneratorProps> {
6-
onSort?(): void;
76
}
87

98
const TableHeader: React.FC<ITableHeaderProps> = (props) => {
@@ -31,10 +30,14 @@ const TableHeader: React.FC<ITableHeaderProps> = (props) => {
3130
content = column.headerRender(column.headerValue, cellContextDetails);
3231
}
3332

33+
function onSortHelper(): void {
34+
column.onSort?.();
35+
}
36+
3437
return (
3538
<th
39+
onClick={onSortHelper}
3640
style={column.headerCellStyle}
37-
onClick={props.onSort}
3841
>
3942
{content}
4043
</th>
@@ -53,8 +56,4 @@ const TableHeader: React.FC<ITableHeaderProps> = (props) => {
5356
);
5457
};
5558

56-
TableHeader.defaultProps = {
57-
onSort: () => {},
58-
};
59-
6059
export default TableHeader;

0 commit comments

Comments
 (0)