0

I'm on CraftCMS 4.6.1

This element uses a custom table and manages quote requests. The problem I'm having is that I cannot seem to dictate the name of the header column used for the primary key id which is the "link" that you click on the element index page to "edit/process" the request. The platform is forcing the header to be Quote Request which is the output from my displayName() method. When I try to specify an override for the column name in the defineTableAttributes() method as shown below, the column is simpliy duplicated with "ID" header but without links. This duplicated column has all of the desired sorting function but it comes at the cost of a "duplicated column" which I want to avoid.

In my custom Element Class I have the following setup:

My display name is set via:

public static function displayName(): string
{
    return 'Quote Request';
}

I defined my table attributes like this:

protected static function defineTableAttributes(): array
{
    return [
        'id' => 'ID',
        'firstName' => 'First Name',
        'lastName' => 'Last Name',
        'company' => 'Company',
        'sent' => 'Completed',
        'promoCode' => 'Promo Code',
        'dateCreated' => 'Created On',
    ];
}

I specify my sort options like so:

protected static function defineSortOptions(): array
{
    return array_merge([
        'id' => [
            'label' => 'ID',
            'orderBy' => 'elements.id',
            'attribute' => 'id',
            'defaultDir' => 'desc',
        ]
    ], parent::defineSortOptions());
}

This results in the column being duplicated, and the duplicate column (without links) allows you to click the header to toggle sort direction, and also works with the sort controls above the table.

If I remove the 'id' => 'ID', line from the defineTableAttributes() method, the column is no longer duplicated (only the default Quote Request column is present, and you can still use the sort controls above the table to sort the list by that column, but in this case the sort controls panel still refers to the column as "ID" as specified. Furthermore, the directional sort arrow is not added to the first column header like it does with the duplicated column when present.

Even hovering the first (forced/default) column header does not "highlight" the cell to indicate it is even clickable (because it isn't).

Here is a screenshot showing what I mean: enter image description here

When I add the ID column back via my defineTableAttributes() method, this is what the duplication looks like and as you can see works as desired, but is now a duplicate column which I do not want: enter image description here

The main question: How can I get the main/default column header to say ID instead of "Quote Request" and have all of the normal sorting functionality that the other columns enjoy?

Is changing displayName() my only option for the header column title? Does this not affect anything else? I only want the column header to display ID but I still want this class to be referred to as a "Quote Request" in other contexts...

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.