Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add dynamic filters to tables

  • Loading branch information...
commit 4be645e1b44279ec4779eda4b2d4e39e41e2fdab 1 parent afcbfc4
@adrianheine adrianheine authored
Showing with 44 additions and 9 deletions.
  1. +0 −1  style.css
  2. +44 −8 syntax/table.php
View
1  style.css
@@ -43,7 +43,6 @@ div.dataplugin_entry.hidden {
display: none;
}
-
/* default styles for the tag cloud */
ul.dataplugin_cloud {
overflow: auto;
View
52 syntax/table.php
@@ -66,6 +66,7 @@ function handle($match, $state, $pos, &$handler){
$data = array('classes' => $class,
'limit' => 0,
+ 'dynfilters' => false,
'headers' => array());
// parse info
@@ -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);
}
@@ -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'].'">';
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.