Skip to content

Commit

Permalink
Add ant-table-last-header-cell className
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Dec 2, 2019
1 parent b04dca8 commit 586678b
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/TableHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import classNames from 'classnames';
import TableHeaderRow from './TableHeaderRow';
import {
ColumnType,
Expand All @@ -10,24 +11,41 @@ import {
GetComponentProps,
} from './interface';

function getHeaderRows(columns: InternalColumnType[], currentRow = 0, rows: Cell[][] = []) {
function getHeaderRows({
columns = [],
currentRow = 0,
rows = [],
prefixCls,
}: {
columns?: InternalColumnType[];
currentRow?: number;
rows?: Cell[][];
prefixCls: string;
}) {
// eslint-disable-next-line no-param-reassign
rows[currentRow] = rows[currentRow] || [];

columns.forEach(column => {
columns.forEach((column, i) => {
if (column.rowSpan && rows.length < column.rowSpan) {
while (rows.length < column.rowSpan) {
rows.push([]);
}
}
const cell: Cell = {
key: column.key,
className: column.className || '',
className: classNames(column.className, {
[`${prefixCls}-last-header-cell`]: i === columns.length - 1,
}),
children: column.title,
column,
};
if (column.children) {
getHeaderRows(column.children, currentRow + 1, rows);
getHeaderRows({
columns: column.children,
currentRow: currentRow + 1,
rows,
prefixCls,
});
}
if ('colSpan' in column) {
cell.colSpan = column.colSpan;
Expand Down Expand Up @@ -58,7 +76,10 @@ const TableHeader: React.FC<TableHeaderProps> = (props, { table }) => {
return null;
}

const rows = getHeaderRows(columns);
const rows = getHeaderRows({
columns,
prefixCls,
});

expander.renderExpandIndentCell(rows, fixed);

Expand Down

0 comments on commit 586678b

Please sign in to comment.