Skip to content
This repository was archived by the owner on Aug 18, 2022. It is now read-only.

Repository files navigation

Added to monorepo

SortableColumns has been included into the core repository.

SortableColumns

SortableColumns is a Zikula component to help manage data table column headings that can be clicked to sort the data. The collection is an Doctrine\Common\Collections\ArrayCollection of Zikula\Component\SortableColumns\Column objects. Use SortableColumns::generateSortableColumns to create an array of attributes (url, css class) indexed by column name which can be used in the generation of table headings/links.

Controller:

useZikula\Component\SortableColumns\SortableColumns;
// in controller method$orderBy = $request->query->get('orderby', 'pageid');
$currentSortDirection = $request->query->get('sdir', Column::DIRECTION_DESCENDING);
$sortableColumns = newSortableColumns($this->get('router'), 'zikulapagesmodule_admin_index', 'orderby', 'sdir');
$sortableColumns->addColumn(newColumn('pageid')); // first added is automatically the default$sortableColumns->addColumn(newColumn('title'));
$sortableColumns->addColumn(newColumn('cr_date'));
$sortableColumns->setOrderBy($sortableColumns->getColumn($orderBy), $currentSortDirection);
$sortableColumns->setAdditionalUrlParameters(array(
'language' => isset($filterData['language']) ? $filterData['language'] : null,
));
$templateParameters['sort'] = $sortableColumns->generateSortableColumns();

Twig template:

<tr>
<th><aclass='{{ sort.pageid.class }}'href='{{ sort.pageid.url }}'>{% trans %}ID{% endtrans %}</a></th>
<th><aclass='{{ sort.title.class }}'href='{{ sort.title.url }}'>{% trans %}Title{% endtrans %}</a></th>
<th><aclass='{{ sort.cr_date.class }}'href='{{ sort.cr_date.url }}'>{% trans %}Created{% endtrans %}</a></th>
</tr>

Additional shortcut methods are available:

  • $sortableColumns->addColumns()
  • $sortableColumns->setOrderByFromRequest()
$sortableColumns->addColumns([newColumn('pageid'), newColumn('title'), newColumn('cr_date')]);
$sortableColumns->setOrderByFromRequest($request);

If needed, you can obtain the values of the orderByFields (e.g. for a DB query) using:

$sortableColumns->getSortColumn()->getName()
$sortableColumns->getSortDirection()

About

SortableColumns is a zikula component to help manage data table column headings that can be clicked to sort the data

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages