Skip to content

add tooltips | fix data render #920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-data-table-component",
"version": "7.2.1",
"version": "7.3.0",
"description": "A simple to use declarative react based data table",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down Expand Up @@ -50,14 +50,14 @@
"@storybook/theming": "^6.3.8",
"@testing-library/react": "^12.1.0",
"@types/faker": "^5.5.8",
"@types/jest": "^27.0.1",
"@types/jest": "^27.0.2",
"@types/lodash-es": "^4.17.5",
"@types/lodash.orderby": "^4.6.6",
"@types/node": "^16.9.1",
"@types/react": "^17.0.20",
"@types/node": "^16.9.6",
"@types/react": "^17.0.24",
"@types/react-dom": "^17.0.9",
"@types/styled-components": "^5.1.14",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"axios": "^0.21.4",
"babel-eslint": "^10.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@ function DataTable<T>(props: TableProps<T>): JSX.Element {
}
}, [paginationTotalRows]);

// handle updating data and persisting sort state when data changes after initial re-render
useDidUpdateEffect(() => {
dispatch({
type: 'UPDATE_ROWS',
rows: setRowData(data, defaultSortColumn?.selector, defaultSortDirection, sortServer, sortFunction),
rows: setRowData(data, selectedColumn?.selector, sortDirection, sortServer, sortFunction),
});
}, [data]);

Expand Down
14 changes: 12 additions & 2 deletions src/DataTable/TableCol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const sortableCSS = css<ColumnSortableProps>`
const ColumnSortable = styled.div<ColumnSortableProps>`
align-items: center;
height: 100%;
line-height: 1.5;
outline: none;
user-select: none;
display: inline-flex;
Expand Down Expand Up @@ -125,6 +124,15 @@ function TableCol<T>({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const [showTooltip, setShowTooltip] = React.useState(false);
const columnRef = React.useRef<HTMLDivElement | null>(null);

React.useEffect(() => {
if (columnRef.current) {
setShowTooltip(columnRef.current.scrollWidth > columnRef.current.clientWidth);
}
}, [showTooltip]);

if (column.omit) {
return null;
}
Expand Down Expand Up @@ -223,7 +231,9 @@ function TableCol<T>({
{!disabled && nativeSortIconRight && renderNativeSortIcon(sortActive)}

{typeof column.name === 'string' ? (
<ColumnText data-column-id={column.id}>{column.name}</ColumnText>
<ColumnText title={showTooltip ? column.name : undefined} ref={columnRef} data-column-id={column.id}>
{column.name}
</ColumnText>
) : (
column.name
)}
Expand Down
Loading