Skip to content

Commit

Permalink
Allow decimals in column widths, also fix resiverobserver handling in…
Browse files Browse the repository at this point in the history
… Firefox
  • Loading branch information
nstepien committed Jan 13, 2021
1 parent 6d5ce5d commit 348b639
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/hooks/useGridDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export function useGridDimensions(): [React.RefObject<HTMLDivElement>, number, n
// don't break in jest/jsdom and browsers that don't support ResizeObserver
if (ResizeObserver == null) return;

const resizeObserver = new ResizeObserver(entries => {
const { width, height } = entries[0].contentRect;
setGridWidth(width);
setGridHeight(height);
const resizeObserver = new ResizeObserver(() => {
// Get dimensions without scrollbars.
// The dimensions given by the callback entries in Firefox do not substract the scrollbar sizes.
const { clientWidth, clientHeight } = gridRef.current!;
setGridWidth(clientWidth);
setGridHeight(clientHeight);
});

resizeObserver.observe(gridRef.current!);
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/useViewportColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ export function useViewportColumns<R, SR>({
}

const unallocatedWidth = viewportWidth - allocatedWidth;
const unallocatedColumnWidth = Math.max(
Math.floor(unallocatedWidth / unassignedColumnsCount),
minColumnWidth
);
const unallocatedColumnWidth = unallocatedWidth / unassignedColumnsCount;

for (const column of columns) {
let width;
Expand Down

4 comments on commit 348b639

@mdodge-ecgrow
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to figure out how to install this specific commit. This is what I've tried: npm i git+https://github.com/adazzle/react-data-grid.git#348b639. And getting nasty errors in my IDE when trying to compile. What am I doing wrong?

@nstepien
Copy link
Contributor Author

@nstepien nstepien commented on 348b639 Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdodge-ecgrow You'll need to build react-data-grid, something like this should work:

cd node_modules/react-data-grid
npm run prepublishOnly

@mdodge-ecgrow
Copy link

@mdodge-ecgrow mdodge-ecgrow commented on 348b639 Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting this error when i run the prepublishOnly inside the react-data-grid folder.

[!] Error: Could not resolve entry module (rollup.config.js).
Error: Could not resolve entry module (rollup.config.js).
    at error (C:\...\node_modules\react-data-grid\node_modules\rollup\dist\shared\rollup.js:5265:30)
    at ModuleLoader.loadEntryModule (C:\...\node_modules\react-data-grid\node_modules\rollup\dist\shared\rollup.js:18470:20)
    at async Promise.all (index 0)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `rollup --config --no-stdin`
npm ERR! Exit status 1

@nstepien
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've published [email protected] if you wanna try.

Please sign in to comment.