Skip to content
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

Dynamic column #1144

Merged
merged 9 commits into from
Jan 20, 2025
Merged

Dynamic column #1144

merged 9 commits into from
Jan 20, 2025

Conversation

chu-shen
Copy link
Contributor

Support dynamic columns and adjust column width

default:
image

dynamic columns:
image

adjust column width:
image
cursor:
image
After changing the column width, the page needs to be manually refreshed

#669 #676

Copy link
Owner

@Difegue Difegue left a comment

Choose a reason for hiding this comment

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

Wow, I never thought anyone would tackle this!
I have some remarks on the dynamic column count feature but overall it's pretty good, it follows on the original logic which was already (almost) expandable.

The resizable columns are a bit rough but hopefully it can be smoothed out. (Otherwise, I'd be happy just merging the dynamic columns first! We'll see)

locales/template/en.po Outdated Show resolved Hide resolved
localStorage.setItem(`resizeColumn${index}`, currentHeader.style.width);
currentHeader = null;
}
document.removeEventListener('mousemove', resizeColumn);
Copy link
Owner

Choose a reason for hiding this comment

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

I feel like this function needs a way to block the sort-on-click behavior that datatables has;

Currently if I drag to resize a column and release the mouse while in the column, it'll trigger a sort, which is very disorienting and resets the column width.

Screen.Recording.2024-12-31.043918.mp4


function resizeColumn(event) {
if (currentHeader) {
const newWidth = startWidth + (event.clientX - startX);
Copy link
Owner

Choose a reason for hiding this comment

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

This calculation is very inaccurate to me some times - I have to drag the mouse pretty far before the column width starts reacting (as seen in the screen recording in the other comment)

Some other times, it will violently snap the column width to a very different value as soon as I start sliding.

@@ -638,11 +636,9 @@ body.swal2-shown>[aria-hidden="true"] {
}

#i2,
#customheader1,
#customheader2,
[id^="customheader"],
Copy link
Owner

Choose a reason for hiding this comment

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

These changes seem to only collapse the headers, not the columns.
image

templates/index.html.tt2 Outdated Show resolved Hide resolved
public/js/index_datatables.js Outdated Show resolved Hide resolved
@chu-shen
Copy link
Contributor Author

maybe fix:

  • block the sort-on-click
  • resizeColumn
msedge_N2WmdGkdhh.mp4

@@ -819,6 +819,7 @@ Index.resizableColumns = function () {
// init
header.addEventListener('mousedown', function (event) {
if (event.offsetX > header.offsetWidth - 10) {
event.preventDefault();
Copy link
Owner

Choose a reason for hiding this comment

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

This change doesn't seem to fix anything for me on Firefox unfortunately.

@@ -856,6 +858,8 @@ Index.resizableColumns = function () {
document.removeEventListener('mousemove', resizeColumn);
document.removeEventListener('mouseup', stopResize);
document.body.style.cursor = 'default';

document.location.reload(true);
Copy link
Owner

Choose a reason for hiding this comment

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

This makes the behavior worse it seems, the columns seemed to resize and remember their size fine without needing a page reload here.

In fact it's worse now, since there appears to be some kind of race condition that prevents the column size from being saved in localStorage before the page reloads.

@chu-shen
Copy link
Contributor Author

chu-shen commented Jan 3, 2025

There seems to be no problem on Firefox v125.0 Portable

firefox_xNLIIJ8kPc.mp4

image

@Difegue
Copy link
Owner

Difegue commented Jan 10, 2025

Hmm, I'm on 133 but I wouldn't expect that to cause any issues - I'll recheck at some point.

@Difegue
Copy link
Owner

Difegue commented Jan 20, 2025

Turns out using offsetWidth doesn't really work depending on DPI scaling on the host browser side -- I fixed that by using localStorage and width whenever possible.

I also cleaned up some more logic to avoid the resizes weirdly jumping around and clamped the resizes by min/maxwidth.

I took a sidetrip to see if we couldn't use a datatables plugin for the resizes, but the one I found wasn't really better than what you'd already implemented. 🤝

Thanks for the help!

@Difegue Difegue merged commit b77b92c into Difegue:dev Jan 20, 2025
2 of 3 checks passed
@chu-shen chu-shen deleted the dynamicColumn branch January 23, 2025 12:02
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.

Resizeable columns in list view [Feature Request] More custom columns for main page
2 participants