Skip to content

Commit

Permalink
Add dynamic filters to tables
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Dec 8, 2010
1 parent afcbfc4 commit 4be645e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
1 change: 0 additions & 1 deletion style.css
Expand Up @@ -43,7 +43,6 @@ div.dataplugin_entry.hidden {
display: none;
}


/* default styles for the tag cloud */
ul.dataplugin_cloud {
overflow: auto;
Expand Down
52 changes: 44 additions & 8 deletions syntax/table.php
Expand Up @@ -66,6 +66,7 @@ function handle($match, $state, $pos, &$handler){

$data = array('classes' => $class,
'limit' => 0,
'dynfilters' => false,
'headers' => array());

// parse info
Expand Down Expand Up @@ -140,6 +141,9 @@ function handle($match, $state, $pos, &$handler){
case 'target':
$data['page'] = cleanID($line[1]);
break;
case 'dynfilters':
$data['dynfilters'] = (bool) $line[1];
break;
default:
msg("data plugin: unknown option '".hsc($line[0])."'",-1);
}
Expand Down Expand Up @@ -219,6 +223,19 @@ function render($format, &$R, $data) {

function preList($clist, $data) {
global $ID;

// Save current request params to not loose them
$cur_params = array();
if(isset($_REQUEST['dataflt'])){
$cur_params = $this->dthlp->_a2ua('dataflt', $_REQUEST['dataflt']);
}
if (isset($_REQUEST['datasrt'])) {
$cur_params['datasrt'] = $_REQUEST['datasrt'];
}
if (isset($_REQUEST['dataofs'])) {
$cur_params['dataofs'] = $_REQUEST['dataofs'];
}

// build table
$text = '<div class="table dataaggregation">'
. '<table class="inline dataplugin_table '.$data['classes'].'">';
Expand All @@ -239,18 +256,37 @@ function preList($clist, $data) {
}
}

// keep url params
$params = $this->dthlp->_a2ua('dataflt',$_REQUEST['dataflt']);
$params['datasrt'] = $ckey;
$params['dataofs'] = $_REQUEST['dataofs'];

// clickable header
$text .= '<a href="'.wl($ID,$params).
// Clickable header for dynamic sorting
$text .= '<a href="'.wl($ID,array('datasrt' => $ckey)+$cur_params).
'" title="'.$this->getLang('sort').'">'.hsc($head).'</a>';

$text .= '</th>';
}
$text .= '</tr>';

// Dynamic filters
if ($data['dynfilters']) {
$text .= '<tr>';
foreach($data['headers'] as $num => $head){
$text .= '<th>';
$form = new Doku_Form(array('method' => 'GET'));
$form->_hidden = array();
$key = 'dataflt[' . $clist[$num] . '*~' . ']';
$val = isset($cur_params[$key]) ? $cur_params[$key] : '';

// Add current request params
foreach($cur_params as $c_key => $c_val) {
if ($c_val !== '' && $c_key !== $key) {
$form->addHidden($c_key, $c_val);
}
}

$form->addElement(form_makeField('', $key, $val, ''));
$text .= $form->getForm();
$text .= '</th>';
}
$text .= '</tr>';
}

return $text;
}

Expand Down

0 comments on commit 4be645e

Please sign in to comment.