Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holisticnetworking/cd6fb9b7745e08eb6fcb01eef094930a to your computer and use it in GitHub Desktop.
Save holisticnetworking/cd6fb9b7745e08eb6fcb01eef094930a to your computer and use it in GitHub Desktop.
Displaying a list of column headers from an arbitrary number of columns.
/*
* Display column headers for the user-selected array of columns.
*
* @var str $query: The query array.
*/
public function displayColumnHeaders( $query ) {
$headers = '';
$sort = $query['sort'];
$direction = $query['direction'];
$arrow = sprintf('fa fa-sort-%s', $direction);
$this->Paginator->options([
'defaultModel' => 'Invoices'
]);
foreach( $this->activeColumns as $key=>$meta ) :
if(in_array($meta['sort_index'], $this->noSort)) :
$content = $meta['label'];
elseif($sort==$meta['sort_index']) :
$content = $this->Paginator->sort(
$meta['sort_index'],
sprintf(
'<i class="%s sort-arrow">&nbsp;</i><span class="sort-text">%s</span>',
$arrow,
$meta['label']
),
[
'escape' => false,
'direction' => ($direction == 'ASC') ? 'DESC' : 'ASC'
]
);
else :
$content = $this->Paginator->sort( $meta['sort_index'], $meta['label'] );
endif;
$headers .= sprintf(
'<th scope="col %s">%s</th>',
$key,
$content
);
endforeach;
return $headers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment