Skip to content

[BUGFIX] Table: align filter rows with table columns - #755

Open
Aln999 wants to merge 1 commit into
perses:mainfrom
Aln999:fix/table-filter-scroll-alignment
Open

[BUGFIX] Table: align filter rows with table columns #755
Aln999 wants to merge 1 commit into
perses:mainfrom
Aln999:fix/table-filter-scroll-alignment

Conversation

@Aln999

@Aln999 Aln999 commented Jul 26, 2026

Copy link
Copy Markdown

Description

This PR fixes the filter row alignment issue when the table is scrolled horizontally. It keeps the filter row aligned with the table columns, ensures the filter widths stay in sync, and fixes the filter search so it matches the displayed values correctly

Screenshots

Screen.Recording.2026-07-26.230445.mp4

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.

#Relates to perses/perses#3835

Signed-off-by: Tanvi Kuchanur <alnk8465@gmail.com>
@Aln999
Aln999 requested a review from a team as a code owner July 26, 2026 17:39
@Aln999
Aln999 requested review from jgbernalp and removed request for a team July 26, 2026 17:39
@shahrokni
shahrokni self-requested a review July 27, 2026 07:50
const syncFilterRowScroll = (): void => {
filterRowInner.style.transform = `translateX(-${scrollContainer.scrollLeft}px)`;

setOpenFilterColumn((current) => (current === null ? current : null));

@shahrokni shahrokni Jul 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems the set value is null anyway.
Your logic => if current is null set it to current, otherwise set it to null.
So, couldn't you simply do something like this? Am I missing something?

setOpenFilterColumn(null);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are right
Simplified to a plain

setOpenFilterColumn(null).

syncColumnWidths();

// Re-sync whenever the header row's size changes
const headerRow = scrollContainer.querySelector('thead tr');

@shahrokni shahrokni Jul 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could've lifted this line up next to the

const scrollContainer = panelContainerRef.current?.querySelector<HTMLElement>('.MuiTableContainer-root');
const headerRow = scrollContainer?.querySelector('thead tr');

if(!headerRow){
   return;
}

With an early return you could've avoided the execution of some lines and also unnecessary heap memory consumption. WDYT? But before taking any action, does it make sense to initially call syncColumnWidths(); even if headerRow is undefined? Because, if this is the case, my suggestion does not make any sense.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right, it doesn't make sense to run syncColumnWidths() without a header row. Rearranged to return early

Comment on lines +848 to +855
{columns.map((column, idx) => {
const filters = getSelectedFilterValues(column.accessorKey as string);
const columnWidth = column.width || spec.defaultColumnWidth;
const anchorEl = filterAnchorEl[column.accessorKey as string];

return (
<div
key={`filter-${idx}`}

@shahrokni shahrokni Jul 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know this is the legacy part. But let's see if we can improve it.
Although the code is looping over the columns the return element key has been named filter-${idx}
Probably the key should've included column-${something}
Now, lets say my assumption is correct (we need to check that first)
Then the key is not really performant. According to official React docs, assigning an index-based key is not a good idea. So, couldn't the original developer utilize column.accessorKey, it seems it is unique. Let's take a look and see if we can improve this key carefully. (Make sure accessorKey is unique)

position: 'fixed',
top: anchorEl.getBoundingClientRect().bottom + 4,
left: anchorEl.getBoundingClientRect().left,
zIndex: 1300,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where does this 1300 come from? Any logic or specific reason?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

no good reason to hard-code it. It happens to match MUI's own theme.zIndex.modal so I've referenced that directly instead of the magic number. Will update it to

zIndex: theme.zIndex.modal,

@shahrokni

Copy link
Copy Markdown
Contributor

@Aln999
You also need to rebase main

This branch is out-of-date with the base branch
Merge the latest changes from main into this branch

Please let me know if you need help for that

@shahrokni

Copy link
Copy Markdown
Contributor

@Aln999
You have failing pipelines. Please take a look and resolve the issues. The issues are tiny.
Since, the pipeline is not automatically running automatically after every push, you can check the linters, tests, etc locally to make sure that everything is in order before pushing to the remote side.

@shahrokni

Copy link
Copy Markdown
Contributor

@Aln999
There is an old bug here and I am wondering, if this is the best time to get rid of it! However, if it only takes less than an hour!
So, feel free to ignore this one, if it demands some times and effort.
You see the filter button here? The click wouldn't close the filter. Could we fix this?

image

@shahrokni

shahrokni commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

I tested the table PR and your fix amazingly have made it way better! I really appreciate for the contribution. I tried to be picky and find something to complain about but I couldn't! Thank you @Aln999 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants