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

Empty GridField without actions creates a 'No items found' row hardcoded to span only two columns #1859

Open
2 tasks done
Kevinn1109 opened this issue Nov 22, 2024 · 0 comments

Comments

@Kevinn1109
Copy link

Kevinn1109 commented Nov 22, 2024

Module version(s) affected

2.1.16

Description

When a GridField has no items, normally a row spanning all columns is inserted with the text 'No items found'. However, when the GridField is given no actions, this row is fixed to span only two columns.
Screenshot 2024-11-22 at 11 20 19

This is caused by the 'hacky' fix for silverstripe/silverstripe-framework#7610, which makes clear that this code exists so that an additional column could be added. This works fine if there's one cell for each column, since only the last cell is changed to span two columns, but doesn't in this particular situation.

The colspan change happens in

fixColumns: function (visible) {
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 $extraCell = $('<th class="extra" />');
$('.grid-field__filter-header th:last .action').each(function() {
$(this).detach();
$extraCell.append($(this));
});
$('.grid-field__filter-header').append($extraCell);
},

How to reproduce

public function getCMSFields() {
  $fields = parent::getCMSFields();
  $gridField = GridField::create("EmptyRelation", "EmptyRelation", DataObject2::get()->where(["ID" => 0]);
  $gridField->getConfig()->removeComponentsByType([GridFieldAddNewButton::class, GridFieldAddExistingAutocompleter::class]);
  $fields->addFieldToTab("Root.EmptyRelation", $gridField);
  return $fields;
}

Possible Solution

This code seems to have been added to create space for a search button in SS3. This search button doesn't seem to exist anymore, so complete removal of this function may do the trick without consequences.

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)

PRs

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

No branches or pull requests

2 participants