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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Dynamic column #1144

wants to merge 6 commits into from

Conversation

chu-shen
Copy link

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
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
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.

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