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

FIX Add one to current colspan in fixColumns instead of resetting to 2 #1869

Open
wants to merge 1 commit into
base: 2.3
Choose a base branch
from

Conversation

Kevinn1109
Copy link

Description

In the old situation, the final column in each row would be hardcoded to colspan="2" if the function 'fixColumns' was called. This is required because this function adds an additional column to the table that needs to be filled in. This change removes the hardcoded number and instead adds one to the current colspan of the last cell. This fixes the bug that the 'No items found' row would be capped at two columns even if the table has more.

Manual testing steps

  1. Manually create a GridField for an has_many relation that contains no records, this should fullfill the check in needsColumnFix by default. The relation class should have at least 3 summary fields.
  2. Without this change, the 'No items found' row gets a colspan of 2. With this change, it should be 4.

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@Kevinn1109 Kevinn1109 force-pushed the bugfix/no-records-row-colspan branch 3 times, most recently from ee22a35 to ae3f7db Compare December 10, 2024 10:21
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Thanks! Couple of small changes

@@ -176,7 +176,8 @@ $.entwine('ss', function($) {
this.find('.sortable-header').append('<th class="main col-Actions" />');
this.find('tbody tr').each(function () {
var cell = $(this).find('td:last');
cell.attr('colspan', 2);
var colspan = cell.attr("colspan") ?? 1;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var colspan = cell.attr("colspan") ?? 1;
var colspan = cell.attr('colspan') ?? 1;

What is the ?? 1 there for? What scenarios result in there not being a colspan attribute?

Copy link
Author

Choose a reason for hiding this comment

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

The colspan attribute is not set by default, I've not seen it in use other than in the case of an empty gridfield.

Copy link
Member

Choose a reason for hiding this comment

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

Would colspan 2 always be correct when colspan wasn't already defined?

client/src/legacy/GridField.js Show resolved Hide resolved
@@ -176,7 +177,8 @@ $.entwine('ss', function($) {
this.find('.sortable-header').append('<th class="main col-Actions" />');
this.find('tbody tr').each(function () {
var cell = $(this).find('td:last');
cell.attr('colspan', 2);
var colspan = cell.attr('colspan') ?? 1;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var colspan = cell.attr('colspan') ?? 1;
// Note we need to add 1 to the current column span, because we're going to add a new column
var colspan = cell.attr('colspan') ?? 1;

@@ -176,7 +176,8 @@ $.entwine('ss', function($) {
this.find('.sortable-header').append('<th class="main col-Actions" />');
this.find('tbody tr').each(function () {
var cell = $(this).find('td:last');
cell.attr('colspan', 2);
var colspan = cell.attr("colspan") ?? 1;
Copy link
Member

Choose a reason for hiding this comment

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

Would colspan 2 always be correct when colspan wasn't already defined?

In the previous situation, the 'No items found' row would be hardcapped at colspan=2. This change ensures that that row always spans all columns in the table
@Kevinn1109 Kevinn1109 force-pushed the bugfix/no-records-row-colspan branch from 8d14019 to 3d6b2d9 Compare December 17, 2024 08:20
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