Skip to content
Snippets Groups Projects
Commit bb29ccb9 authored by Tim Steiner's avatar Tim Steiner
Browse files

Update the CollectionTable View Helper to sort using jQuery TableSort

parent 8f7c2e9d
No related branches found
No related tags found
No related merge requests found
<?php
class App_View_Helper_CollectionTable extends Zend_View_Helper_Abstract
{
public function collectionTable(Unl_Model_Collection $collection,
static protected $_uniqueIndex = 0;
public function collectionTable(Unl_Model_Collection $collection,
array $columns,
array $searchUrlParameters = null,
array $formatOptions = null,
$rowClassColumn = null)
{
$this->view->headScript()->appendFile('http://tablesorter.com/jquery.tablesorter.min.js');
self::$_uniqueIndex++;
if (!is_array($searchUrlParameters)) {
$searchUrlParameters = array();
......@@ -17,18 +21,24 @@ class App_View_Helper_CollectionTable extends Zend_View_Helper_Abstract
$output = '';
$output .= "<table>\n";
$output .= '<table id="collectionTable' . self::$_uniqueIndex . '" class="collectionTable">' . "\n";
$output .= "<thead>\n";
$output .= "<tr>\n";
foreach ($columns as $field => $title) {
$output .= "<th>\n";
if ($field[0] != '#') {
$output .= '<a href="'
/*
$output .= '<a href="'
. $this->view->url(array_merge($searchUrlParameters, array('sort' => $field)))
. '">' . $title . '</a>' . "\n";
*/
$output .= $title;
}
$output .= "</th>\n";
}
$output .= "</tr>\n";
$output .= "</thead>\n";
$output .= "<tbody>\n";
foreach ($collection as $row) {
$rowClasses = array();
if ($rowCount++ % 2) {
......@@ -56,8 +66,15 @@ class App_View_Helper_CollectionTable extends Zend_View_Helper_Abstract
}
$output .= "</tr>\n";
}
$output .= "</tbody>\n";
$output .= "</table>\n";
$output .= '<script type="text/javascript">' . PHP_EOL
. '$(document).ready(function() {' . PHP_EOL
. ' $("#collectionTable' . self::$_uniqueIndex . '").tablesorter({widgets: ["zebra"]});' . PHP_EOL
. '});' . PHP_EOL
. '</script>' . PHP_EOL;
return $output;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment