3

When adding a custom column to an Entry List view using the modifyEntryTableAttributes hook, how would you also set the display order of columns?

4

You need to reorder the $attributes array to do this. You can do this in various ways, here is how I would do it depending on the position you wanted for the new column:

public function modifyEntryTableAttributes(&$attributes, $source)
{
    if ($source == 'section:3')
    {
        // insert column in first position (using array_merge)
        $attributes = array_merge(array(['id'] => Craft::t('ID'), $attributes);

        // insert column in fourth position (using array_splice)
        array_splice($attributes, 3, 0, array('id' => Craft::t('ID')));  
    }
}
2

As far as I can tell, you would need to unset all of the native columns and then reset them in the desired order.

public function modifyEntryTableAttributes(&$attributes, $source)
{
    if ($source == 'section:3')
    {
        // unset all column attributes
        unset($attributes['title']);
        unset($attributes['uri']);
        unset($attributes['postDate']);
        unset($attributes['expiryDate']);

        // set column attributes in the desired order
        $attributes['id'] = Craft::t('ID');
        $attributes['title'] = Craft::t('Title');
        $attributes['uri'] = Craft::t('URI');
        $attributes['postDate'] = Craft::t('Post Date');
        $attributes['expiryDate'] = Craft::t('Expiry Date');
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.