38 require_once realpath(dirname(__FILE__)).
"/data_column.inc";
39 require_once realpath(dirname(__FILE__)).
"/join.inc";
40 require_once realpath(dirname(__FILE__)).
"/excel.inc";
41 require_once realpath(dirname(__FILE__)).
"/facet_manager.inc";
116 $this->items = $items;
122 $this->cssStyle =
null;
123 $this->emptyMessage =
"No matching items.";
124 $this->onStartRow =
null;
125 $this->excelFile =
null;
126 $this->summary =
null;
128 $this->totalCallbacks = array();
129 $this->tagRowCallbacks = array();
155 $this->sortable =
false;
156 $this->filter =
false;
158 $this->paginate =
false;
159 $this->dragReorder =
true;
161 $this->zebra =
false;
163 $this->reorderHandler = $handler;
178 function column($title, $format,
$sortable =
false, $style =
null, $typeHint =
null, $onExport =
null, $sortFormat =
null)
180 $this->columns[] =
new DataColumn($title, $format,
$sortable, $style, $typeHint, $onExport, $sortFormat);
198 function exportColumn($title, $format,
$sortable =
false, $style =
null, $typeHint =
null, $onExport =
null, $sortFormat =
null)
200 $column =
new DataColumn($title, $format,
$sortable, $style, $typeHint, $onExport, $sortFormat);
201 $column->exportOnly =
true;
202 $this->columns[] = $column;
212 $columnsByTitle =
reindexList($this->columns,
"title");
214 foreach($order as $title)
216 if (array_key_exists($title, $columnsByTitle))
218 $columns[] = $columnsByTitle[$title];
232 if (!$format && count($this->items))
234 $pk = $this->items[0]->primary_key;
235 $format =
"<input type='checkbox' class='checkbox' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
238 if($format ==
"radio" && count($this->items) ){
239 $pk = $this->items[0]->primary_key;
240 $format =
"<input type='radio' class='radio' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
243 $this->
column(
" ", $format,
false,
"text-align: center");
244 $this->selectable =
true;
250 if ($this->rowIdFormat)
252 return $item->format($this->rowIdFormat);
255 $pk = $item->getPrimaryKey();
256 return "{$pk}_" . $item->$pk;
270 $this->menu =
new ContextMenu($this->
id .
"_menu",
"#{$this->id}_menu_button");
271 $this->menu->trigger =
"click";
272 $this->menu->position =
"element";
274 if ($this->showSelectAll)
276 $this->menu->command(
"toggle_select_all",
"Select All",
"new DOMEvent(event).stop(); SortingTable.toggleSelect(this, '{$this->id}');",
false);
295 if ($this->showSelectAll)
297 $this->
contextMenu->command(
"toggle_select_all",
"Select All",
"new DOMEvent(event).stop(); SortingTable.toggleSelect(this, '{$this->id}');",
false);
310 $this->toolbarCallbacks[] = $callback;
347 function footerTotal($field, $style =
"text-align: right", $colspan = 1, $typeHint = Number)
349 $column =
new FooterTotalColumn($field, $template =
"", $style, $colspan, $typeHint);
350 $this->footerColumns[] = $column;
351 $this->totalCallbacks[] = array($column, onStartRow);
362 if ($this->
id)
return;
378 $this->tagRowCallbacks[] = $handler;
397 if (count($this->columns) > 0)
return;
399 $fields = $item->getFieldArray();
400 foreach($fields as $field)
402 if ($item->primary_key == $field)
continue;
404 $this->
column($item->prettifyFieldName($field),
"{".$field.
"}", $true);
416 if ($_REQUEST[
"__column_order"])
421 if ($this->excelFile && $_REQUEST[
"__excel"] == $this->
id)
426 if (count($this->items) == 0)
return;
431 "\t<script type='text/javascript' src='/fakoli/js/sorting_table.js'></script>\n".
432 "\t<script type='text/javascript' src='/fakoli/js/paginating_table.js'></script>\n".
433 "\t<script type='text/javascript' src='/fakoli/js/filtering_table.js'></script>\n".
434 "\t<script type='text/javascript' src='/fakoli/js/scrolling_table.js'></script>\n";
440 if (!$this->sortable && $this->pageSize <= 0 && !$this->filter && !$this->dragReorder)
445 $zebra = $this->zebra ?
"true" :
"false";
447 if ($this->pageSize > 0 AND $this->paginate)
449 $constructor =
"\n\t\tvar {$this->id}_paginator = new PaginatingTable('{$this->id}', '{$this->id}_paginator', {per_page: {$this->pageSize}, zebra: $zebra});";
453 $constructor =
"\n\t\tvar {$this->id}_paginator = false;";
456 if ($this->filter !==
false)
458 $constructor .=
"\n\t\tvar {$this->id}_filter = new FilteringTable('{$this->id}', '{$this->id}_filter', {column: {$this->filter}, paginator: {$this->id}_paginator});";
462 $constructor .=
"\n\t\tvar {$this->id}_filter = false;";
467 $constructor .=
"\n\t\tvar {$this->id}_sort = new SortingTable('{$this->id}', { paginator: {$this->id}_paginator, filter: {$this->id}_filter, zebra: $zebra});";
470 if ($this->selectable)
472 $constructor .=
"\n\t\tdocument.id('{$this->id}').getSelectedValues = function() { var values = []; this.getElements(\"input[type='checkbox']\").each(function(e) { if (e.checked) values.push(e.value); }); return values; };";
477 $constructor .=
"\n\t\tnew ScrollingTable('{$this->id}');";
480 if ($constructor || $this->dragReorder || $this->dragColumnReorder)
482 $script .=
"\t<script type='text/javascript'>\n\twindow.addEvent('domready', function()\n{";
483 $script .= $constructor;
485 if ($this->dragReorder)
487 $script .=
"\n\t\tnew DraggableTable('#{$this->id} tbody', '{$this->reorderHandler}', '{$this->items[0]->primary_key}');";
490 if ($this->dragColumnReorder)
493 $script .=
"\n\tnew DraggableColumnTable('{$this->id}'$options);";
496 $script .=
"\n\t});\n\t</script>\n";
500 if ($this->menu) $script .= $this->menu->writeScript();
511 trace(
"Number of Items: ".count($this->items), 3);
513 if (count($this->items) > 0)
515 if (!count($this->columns)) $this->
autoPopulate($this->items[0]);
519 $attrs .=
" id='{$this->id}'";
524 $attrs .=
" class='{$this->cssClass}";
525 if ($this->sortable) $attrs .=
" sortable";
527 if ($this->dragReorder) $attrs .=
" reorder";
533 $attrs .=
" style='{$this->cssStyle}'";
538 $attrs .=
" summary='".htmlSafe($this->summary).
"'";
546 $width =
'width: 100%';
547 if (preg_match(
"/^\\width:.*?\\d{1,5}px|width:.*?\\d{1,3}%/", $this->cssStyle, $matches))
548 $width = $matches[0];
551 <div style=
"<?echo $width ?>">
556 <div style=
"float: right;" class=
"paginator"><ul
id=
"<?echo $this->id?>_paginator"></ul></div>
563 <div style=
"float: left" class=
"filter" id=
"<?echo $this->id?>_filter"></div>
567 if ($this->dragReorder)
577 $tbodyAttrs =
" style='height: ".($this->height - 24).
"px'";
578 echo
"<div class='scrollContainer' style='height: {$this->height}px'>";
581 <table border=
"0" cellpadding=
"0" cellspacing=
"0"<?echo $attrs?>>
587 foreach($this->columns as $column)
589 if ($column->exportOnly)
continue;
594 if (!$column->sortable)
601 $attrs .=
" class='$cssClass'";
604 if (preg_match(
"/^\\width:.*?\\d{1,3}px|width:.*?\\d{1,3}%/", $column->style, $matches))
606 $attrs .=
" style='{$matches[0]}'";
609 if ($column->sortFormat) $attrs .=
" data-sort='true'";
616 if ($this->excelFile)
621 if ($this->excelFile && !$this->menu && !$this->hideExcelIcon)
624 <a href=
'<?echo $qs?>' style=
"float: left"><img src=
"/fakoli/images/msexcel_icon_small.png" alt=
"Excel" style=
"border: none; display:inline-block;vertical-align: middle"/></a>
627 else if ($this->menu)
629 if ($this->excelFile)
631 $this->menu->command($this->
id.
"_excel",
"Save as Excel...", $qs,
true,
"/fakoli/images/msexcel_icon_small.png");
634 <img
id=
"<?echo $this->id?>_menu_button" src=
"<?echo $this->commandMenuIcon?>" alt=
"Table Menu" style=
"border: none; display:inline-block;vertical-align: middle"/>
640 $this->menu->command($this->
id.
"_context_excel",
"Save as Excel...", $qs,
true,
"/fakoli/images/msexcel_icon_small.png");
643 foreach($this->toolbarCallbacks as $callback)
645 echo
"<div style='display: inline-block; float: left'>";
646 echo call_user_func($callback, $this);
652 <?echo $column->title?></th>
658 <tbody<?echo $tbodyAttrs?>>
660 foreach($this->items as $item)
666 if ($this->onStartRow)
668 $retval = call_user_func($this->onStartRow, $item);
669 if ($retval ===
false)
continue;
670 if ($retval) $cl[] = $retval;
673 $dataAttrs = array();
674 foreach($this->tagRowCallbacks as $cb)
676 $dataAttrs = call_user_func($cb, $item, $dataAttrs);
680 foreach($dataAttrs as $name => $value)
682 $rowAttrs .=
" ".$name.
"='".$value.
"'";
685 foreach($this->totalCallbacks as $cb)
687 call_user_func($cb, $item);
692 if ($this->onRowClick)
694 $onclick =
" onclick=\"" . $item->format($this->onRowClick) .
"\" onmouseover=\"this.addClass('hover');";
695 if ($this->onRowHover) $onlick .= $item->format($this->onRowHover);
696 $onclick .=
" return false;\" onmouseout=\"this.removeClass('hover'); return false;\"";
700 $cl = implode(
" ", $cl);
701 if ($cl) $cl =
"class='$cl'";
704 <tr <?echo $rowId?><?php echo $cl?><?echo $onclick?><?echo $rowAttrs?>>
706 foreach($this->columns as $column)
708 if ($column->exportOnly)
continue;
713 if (preg_match(
"/^[\\w_]*$/", $column->style))
719 $attrs .=
" style='{$column->style}'";
724 $attrs .=
" class='$cssClass'";
727 if ($column->sortFormat) $attrs .=
" data-sort='".htmlentities($item->format($column->sortFormat)).
"'";
729 <td<?echo $attrs?>><?echo $column->format($item)?></td>
739 if ($this->onDrawFooter) call_user_func($this->onDrawFooter);
741 if (count($this->footerColumns) > 0)
747 foreach($this->footerColumns as $column)
753 if (preg_match(
"/^[\\w_]*$/", $column->style))
755 $attrs .=
" class='{$column->style}'";
759 $attrs .=
" style='{$column->style}'";
763 if ($column->colspan > 1)
765 if (!$this->dragColumnReorder)
767 $attrs .=
" colspan='{$column->colspan}'";
769 <td<?echo $attrs?>><?echo $column->format()?></td>
772 else if (preg_match(
"/text-align:\\s*right/i", $column->style))
774 for($i = 1; $i < $column->colspan; ++$i)
776 echo
"<td> </td>";
779 <td<?echo $attrs?>><?echo $column->format()?></td>
785 <td<?echo $attrs?>><?echo $column->format()?></td>
787 for($i = 1; $i < $column->colspan; ++$i)
789 echo
"<td> </td>";
796 <td<?echo $attrs?>><?echo $column->format()?></td>
810 if ($this->menu) echo $this->menu->writeMenu();
815 echo
"<p><em>{$this->emptyMessage}</em></p>";
827 $out = ob_get_contents();
844 foreach($this->columns as $column)
851 foreach($this->items as $item)
854 if ($this->onStartRow)
856 $retval = call_user_func($this->onStartRow, $item);
857 if ($retval ===
false)
continue;
860 foreach($this->totalCallbacks as $cb)
862 call_user_func($cb, $item);
865 foreach($this->columns as $column)
867 if (is_callable($column->onExport))
869 $val = call_user_func($column->onExport, $item, $column);
871 else if ($column->onExport)
873 $val = $item->format($column->onExport);
877 $val = $column->format($item);
880 switch($column->typeHint)
894 $x->writeNumber($r, $c, $val);
899 $val = str_replace(array(
"$",
","), array(
"",
""), $val);
900 $x->writeCurrency($r, $c, $val);
905 $x->writePercentage($r, $c, $val);
911 if (preg_match(
"/^[\\d\\,\\.\\$]+$/", $val))
913 $val = str_replace(array(
"$",
","), array(
"",
""), $val);
914 $x->writeNumber($r, $c, $val);
930 if ($this->footerColumns)
932 foreach($this->footerColumns as $column)
934 $val = $column->format();
936 if (preg_match(
"/^[\\d\\,\\.]+$/", $val))
938 $val = str_replace(
",",
"", $val);
939 $x->writeFooterNumber($r, $c, $val);
946 $c += $column->colspan;
952 session_write_close();
Represents a column in a DataListView output table.
DataListView displays a list of DataItems (or InnerJoinResults) in tabular format.
Text footer column definition.
selector($format="")
Adds a selector column to the DataListView.
$tagRowCallbacks
Array of callbacks for adding extra attributes to each row.
$totalCallbacks
Array of callbacks for totalling columns.
commandMenu()
Adds a command menu to the table that can contain a list of operations that can be performed on subse...
$columnReorderCallback
Javascript callback function that is triggered when columns are reordered.
$id
ID of the table in the output script.
setColumnOrder($order)
Override the column order.
$zebra
Specifies whether alternate rows in the table should be striped.
$onRowClick
Javascript callback function that is triggered with a row is clicked.
$pageSize
Specifies the number of items per page - set to zero for unpaginated.
$cssStyle
Optional additional inline styles to apply to the table.
addToolbarCallback($callback)
Registers a toolbar callback.
footerText($text="", $style="", $colspan=1)
Adds a text column to the table footer.
$rowId
whether to include an id tag for each tr row
$cssClass
Optional CSS class to apply to the table.
addFacetTaggingHandler($handler)
Adds a row tagging handler.
footerValue($callback, $style="", $colspan=1)
Adds a value column to the table footer.
$reorderHandler
Handler script that implements reordering records.
$sortable
Specifies whether to enable client-side sorting for this table.
$onRowHover
Javascript callback function that is triggered with a row is hovered over.
writeExcelFile($file)
Writes the data table out as an Excel File.
$dragColumnReorder
Enable drag & drop column reordering and show/hide capabilities.
$contextMenu
Right-click context menu for selection based operations.
exportColumn($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
Adds a column definition to the DataListView that is only output when exporting the table to Excel.
$paginate
Specifies whether table should be paginated (false for view only pages)
writeScript()
Write the Javascript to implement the table output.
drawViewToString()
Render the table view and return the generated HTML as a string.
enableDragReorder($handler)
Turns on drag & drop item reordering for the table.
contextMenu()
Adds a right-click context menu to the table that can contain a list of operations that can be perfor...
$summary
Human-readable summary of the information contained in the table (for usability/accessiblity purposes...
drawView()
Writes the HTML for the data table to the output buffer.
$menu
Command menu for selection-based operations.
$dragText
Optional text to display above reorderable table.
autoPopulate($item)
Automatically build the table columns from the given DataItem.
$rowIdFormat
Optionally specify a custom row ID format.
$emptyMessage
Message to display when no items are present in the data set.
$onDrawfooter
Callback hook that gets called after all rows have been drawn.
$columns
The column definitions for the table.
$toolbarCallbacks
Override this callback to add toolbar links into the first header cell.
$dragReorder
Enabled drag & drop reordering.
$footerColumns
The footer column definitions for the table.
$onStartRow
Callback hook that gets called at the start of each row.
$hideExcelIcon
Suppress the automatic Excel icon if you want an external link.
$commandMenuIcon
Icon to use for the command menu dropdown.
$excelFile
Filename for automatic Excel export.
$showSelectAll
Show Select All button for selectable tables.
setID($id=null)
Sets the client-side ID for this DataListView.
scrollable($height=300, $resizable=true)
$filter
Specifies whether to enable client-side filtering for this table.
$selectable
Whether the table provides a selection mechanism.
column($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
Adds a column definition to the DataListView.
footerTotal($field, $style="text-align: right", $colspan=1, $typeHint=Number)
Sums the total for a column.
getExcelLink()
Get the Excel Link.
DataListView($items, $id, $cssClass="list", $sortable=true, $pageSize=0, $filter=false)
Creates a new DataListView object.
stripHTMLTags($text)
Removes all HTML tags from the specified string.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
baseURI($uri=null)
Returns the base URI for the current script, with the query string removed.
getFullQueryString($includePOST=true)
Generates a query string containing the values passed to this page.
appendToQueryString($qs, $params)
Appends the specified parameters to the supplied query string.
makeRandomString($len)
Creates a randomized string of characters.
reindexList($list, $field, $autoPromote=true)
Reindex an indexed or grouped query result by a different field.