Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added simple summarizing to datatables

only shown data is summarized, so when a table is filtered only the
filtered data is summarized
  • Loading branch information...
commit e9a41540ebf2554890255e16414055ad3b08b917 1 parent 0d86e67
@splitbrain authored
Showing with 36 additions and 1 deletion.
  1. +1 −1  plugin.info.txt
  2. +35 −0 syntax/table.php
View
2  plugin.info.txt
@@ -1,7 +1,7 @@
base data
author Andreas Gohr
email andi@splitbrain.org
-date 2010-06-08
+date 2011-12-13
name Structured Data Plugin
desc Add and query structured data in your wiki
url http://www.dokuwiki.org/plugin:data
View
35 syntax/table.php
@@ -14,6 +14,8 @@ class syntax_plugin_data_table extends DokuWiki_Syntax_Plugin {
*/
var $dthlp = null;
+ var $sums = array();
+
/**
* Constructor. Load helper plugin
*/
@@ -67,6 +69,7 @@ function handle($match, $state, $pos, &$handler){
$data = array('classes' => $class,
'limit' => 0,
'dynfilters' => false,
+ 'summarize' => false,
'headers' => array());
// parse info
@@ -144,6 +147,9 @@ function handle($match, $state, $pos, &$handler){
case 'dynfilters':
$data['dynfilters'] = (bool) $line[1];
break;
+ case 'summarize':
+ $data['summarize'] = (bool) $line[1];
+ break;
default:
msg("data plugin: unknown option '".hsc($line[0])."'",-1);
}
@@ -213,6 +219,19 @@ function render($format, &$R, $data) {
$data['cols'][$clist[$num]],
$cval,$R);
$R->doc .= $this->after_val;
+
+ // clean currency symbols
+ $nval = str_replace('$€₤','',$cval);
+ $nval = str_replace('/ [A-Z]{0,3}$/','',$nval);
+ $nval = str_replace(',','.',$nval);
+ $nval = trim($nval);
+
+ // summarize
+ if($data['summarize'] && is_numeric($nval)){
+ if(!isset($this->sums[$num])) $this->sums[$num] = 0;
+ $this->sums[$num] += $nval;
+ }
+
}
$R->doc .= $this->after_item;
}
@@ -303,6 +322,22 @@ function nullList($data, $clist, &$R) {
function postList($data, $rowcnt) {
global $ID;
$text = '';
+ // if summarize was set, add sums
+ if($data['summarize']){
+ $text .= '<tr>';
+ $len = count($data['cols']);
+ for($i=0; $i<$len; $i++){
+ $text .= '<td>';
+ if(!empty($this->sums[$i])){
+ $text .= ''.$this->sums[$i];
+ }else{
+ $text .= '&nbsp;';
+ }
+ $text .= '</td>';
+ }
+ $text .= '<tr>';
+ }
+
// if limit was set, add control
if($data['limit']){
$text .= '<tr><th colspan="'.count($data['cols']).'">';

0 comments on commit e9a4154

Please sign in to comment.
Something went wrong with that request. Please try again.