Fakoli Framework
DataListView Class Reference

DataListView displays a list of DataItems (or InnerJoinResults) in tabular format. More...

+ Inheritance diagram for DataListView:
+ Collaboration diagram for DataListView:

Public Member Functions

 DataListView ($items, $id, $cssClass="list", $sortable=true, $pageSize=0, $filter=false)
 Creates a new DataListView object. More...
 
 getID ()
 
 scrollable ($height=300, $resizable=true)
 
 enableDragReorder ($handler)
 Turns on drag & drop item reordering for the table. More...
 
 column ($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
 Adds a column definition to the DataListView. More...
 
 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. More...
 
 setColumnOrder ($order)
 Override the column order. More...
 
 selector ($format="")
 Adds a selector column to the DataListView. More...
 
 formatRowId ($item)
 
 commandMenu ()
 
 addToolbarCallback ($callback)
 Registers a toolbar callback. More...
 
 footerText ($text="", $style="", $colspan=1)
 Adds a text column to the table footer. More...
 
 footerValue ($callback, $style="", $colspan=1)
 Adds a value column to the table footer. More...
 
 footerTotal ($field, $style="text-align: right", $colspan=1, $typeHint=Number)
 Sums the total for a column. More...
 
 setID ($id=null)
 Sets the client-side ID for this DataListView. More...
 
 addFacetTaggingHandler ($handler)
 Adds a row tagging handler. More...
 
 getExcelLink ()
 Get the Excel Link. More...
 
 autoPopulate ($item)
 Automatically build the table columns from the given DataItem. More...
 
 writeScript ()
 Write the Javascript to implement the table output. More...
 
 drawView ()
 Writes the HTML for the data table to the output buffer. More...
 
 writeExcelFile ($file)
 Writes the data table out as an Excel File. More...
 

Public Attributes

 $columns
 The column definitions for the table. More...
 
 $footerColumns
 The footer column definitions for the table. More...
 
 $cssClass
 Optional CSS class to apply to the table. More...
 
 $id
 ID of the table in the output script. More...
 
 $sortable
 Specifies whether to enable client-side sorting for this table. More...
 
 $pageSize
 Specifies the number of items per page - set to zero for unpaginated. More...
 
 $cssStyle
 Optional additional inline styles to apply to the table. More...
 
 $emptyMessage
 Message to display when no items are present in the data set. More...
 
 $onStartRow
 Callback hook that gets called at the start of each row. More...
 
 $onDrawfooter
 Callback hook that gets called after all rows have been drawn. More...
 
 $tagRowCallbacks
 Array of callbacks for adding extra attributes to each row. More...
 
 $totalCallbacks
 Array of callbacks for totalling columns. More...
 
 $filter
 Specifies whether to enable client-side filtering for this table. More...
 
 $excelFile
 Filename for automatic Excel export. More...
 
 $paginate = true
 Specifies whether table should be paginated (false for view only pages) More...
 
 $summary
 Human-readable summary of the information contained in the table (for usability/accessiblity purposes) More...
 
 $zebra
 Specifies whether alternate rows in the table should be striped. More...
 
 $height
 
 $scrollable = false
 
 $resizable = true
 
 $rowId = false
 whether to include an id tag for each tr row More...
 
 $rowIdFormat = null
 Optionally specify a custom row ID format. More...
 
 $dragReorder = false
 Enabled drag & drop reordering. More...
 
 $reorderHandler = null
 Handler script that implements reordering records. More...
 
 $dragColumnReorder = false
 Enable drag & drop column reordering and show/hide capabilities. More...
 
 $columnReorderCallback = null
 Javascript callback function that is triggered when columns are reordered. More...
 
 $hideExcelIcon = false
 Suppress the automatic Excel icon if you want an external link. More...
 
 $onRowClick = null
 Javascript callback function that is triggered with a row is clicked. More...
 
 $onRowHover = null
 Javascript callback function that is triggered with a row is hovered over. More...
 
 $dragText = ""
 Optional text to display above reorderable table. More...
 
 $selectable = false
 Whether the table provides a selection mechanism. More...
 
 $menu = null
 Context menu for selection-based operations. More...
 
 $commandMenuIcon = "/fakoli/images/data_view_menu.png"
 Icon to use for the command menu dropdown. More...
 
 $toolbarCallbacks = array()
 Override this callback to add toolbar links into the first header cell. More...
 

Static Public Attributes

static $includesWritten = false
 

Detailed Description

DataListView displays a list of DataItems (or InnerJoinResults) in tabular format.

The table is optionally sortable and filterable by column, and can be automatically paginated. The full table is sent to the client and sorting, filtering and pagination are handled at the client via Javascript.

DataListViews can also be rendered directly into binary Microsoft Excel format via the writeExcelFile() method.

Author
andy

Definition at line 51 of file data_view.inc.

Member Function Documentation

◆ addFacetTaggingHandler()

DataListView::addFacetTaggingHandler (   $handler)

Adds a row tagging handler.

This function will receive the data item for each row and can add custom attributes to the row tag.

Implements FacetFilterable.

Definition at line 336 of file data_view.inc.

337  {
338  $this->tagRowCallbacks[] = $handler;
339  }

◆ addToolbarCallback()

DataListView::addToolbarCallback (   $callback)

Registers a toolbar callback.

These can be used to add custom controls into the first header cell of the table, next to the Excel export icon or command menu dropdown icon.

Parameters
callable$callbackthe callback function or method

Definition at line 268 of file data_view.inc.

269  {
270  $this->toolbarCallbacks[] = $callback;
271  }

◆ autoPopulate()

DataListView::autoPopulate (   $item)

Automatically build the table columns from the given DataItem.

Not recommended except for quick and dirty pages. This method is called automatically if no columns have been defined before drawing the view.

Parameters
$itemthe item to use as a template for the columns.

Definition at line 355 of file data_view.inc.

356  {
357  if (count($this->columns) > 0) return;
358 
359  $fields = $item->getFieldArray();
360  foreach($fields as $field)
361  {
362  if ($item->primary_key == $field) continue;
363 
364  $this->column($item->prettifyFieldName($field), "{".$field."}", $true);
365  }
366  }
column($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
Adds a column definition to the DataListView.
Definition: data_view.inc:172

◆ column()

DataListView::column (   $title,
  $format,
  $sortable = false,
  $style = null,
  $typeHint = null,
  $onExport = null,
  $sortFormat = null 
)

Adds a column definition to the DataListView.

Parameters
$titlethe title of the column
$formatthe formatter for the column, either as a formatting string or callback function. (For details on format template specifications, see comments above class DataItem function format.)
$sortablewhether this column is sortable
$styleany inline styles specific to this column
$typeHinthint for cell type to use when exporting to Excel
$onExportoptional callback function to format value for Excel
string$sortFormatOptional explicit format to use as the basis for sorting
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 172 of file data_view.inc.

173  {
174  $this->columns[] = new DataColumn($title, $format, $sortable, $style, $typeHint, $onExport, $sortFormat);
175  return $this;
176  }
$sortable
Specifies whether to enable client-side sorting for this table.
Definition: data_view.inc:57
Represents a column in a DataListView output table.
Definition: data_column.inc:38

◆ commandMenu()

DataListView::commandMenu ( )

Definition at line 253 of file data_view.inc.

254  {
255  $this->menu = new ContextMenu($this->id . "_menu", "#{$this->id}_menu_button");
256  $this->menu->trigger = "click";
257  $this->menu->position = "element";
258 
259  return $this->menu;
260  }
$menu
Context menu for selection-based operations.
Definition: data_view.inc:93

◆ DataListView()

DataListView::DataListView (   $items,
  $id,
  $cssClass = "list",
  $sortable = true,
  $pageSize = 0,
  $filter = false 
)

Creates a new DataListView object.

Parameters
array$itemsthe array of DataItems or InnerJoinResults to be displayed
string$idthe client-side ID for this table
string$cssClassOptional CSS class to apply to the table
string$sortableSpecifies whether to enable client-side sorting for this table
integer$pageSizeSpecifies the number of items per page - set to zero for unpaginated
boolean$filterSpecifies whether to enable client-side filtering for this table.

Definition at line 108 of file data_view.inc.

109  {
110  $this->items = $items;
111  $this->id = $id;
112  $this->cssClass = $cssClass;
113  $this->sortable = $sortable;
114  $this->filter = $filter;
115  $this->pageSize = $pageSize;
116  $this->cssStyle = null;
117  $this->emptyMessage = "No matching items.";
118  $this->onStartRow = null;
119  $this->excelFile = null;
120  $this->summary = null;
121  $this->zebra = true;
122  $this->totalCallbacks = array();
123  $this->tagRowCallbacks = array();
124 
125  return $this;
126  }
$sortable
Specifies whether to enable client-side sorting for this table.
Definition: data_view.inc:57
$id
ID of the table in the output script.
Definition: data_view.inc:56
$cssClass
Optional CSS class to apply to the table.
Definition: data_view.inc:55
$filter
Specifies whether to enable client-side filtering for this table.
Definition: data_view.inc:65
$pageSize
Specifies the number of items per page - set to zero for unpaginated.
Definition: data_view.inc:58

◆ drawView()

DataListView::drawView ( )

Writes the HTML for the data table to the output buffer.

Definition at line 467 of file data_view.inc.

468  {
469  trace("Number of Items: ".count($this->items), 3);
470 
471  if (count($this->items) > 0)
472  {
473  if (!count($this->columns)) $this->autoPopulate($this->items[0]); // Autopopulate the column list from the first object, if not specified
474  $attrs = "";
475  if ($this->id)
476  {
477  $attrs .= " id='{$this->id}'";
478  }
479 
480  if ($this->cssClass)
481  {
482  $attrs .= " class='{$this->cssClass}";
483  if ($this->sortable) $attrs .=" sortable";
484  if ($this->scrollable) $attrs.= " scroll";
485  if ($this->dragReorder) $attrs .= " reorder";
486  $attrs .= "'";
487  }
488 
489  if ($this->cssStyle)
490  {
491  $attrs .= " style='{$this->cssStyle}'";
492  }
493 
494  if ($this->summary)
495  {
496  $attrs .= " summary='".htmlSafe($this->summary)."'";
497  }
498 
499  /*
500  * JDG 6/15/2010 - if the cssStyle has a width setting, either px or
501  * &, apply that width style to the filter and paginator to avoid
502  * formatting problems.
503  */
504  $width = 'width: 100%';
505  if (preg_match("/^\\width:.*?\\d{1,5}px|width:.*?\\d{1,3}%/", $this->cssStyle, $matches))
506  $width = $matches[0];
507 
508 ?>
509  <div style="<?echo $width ?>">
510  <?php
511  if($this->pageSize)
512  {
513  ?>
514  <div style="float: right;" class="paginator"><ul id="<?echo $this->id?>_paginator"></ul></div>
515  <?php
516  }
517 
518  if($this->filter)
519  {
520  ?>
521  <div style="float: left" class="filter" id="<?echo $this->id?>_filter"></div>
522  <?php
523  }
524 
525  if ($this->dragReorder)
526  {
527  echo $this->dragText;
528  }
529  ?>
530  </div>
531 
532  <?php
533  if ($this->scrollable)
534  {
535  $tbodyAttrs = " style='height: ".($this->height - 24)."px'";
536  echo "<div class='scrollContainer' style='height: {$this->height}px'>";
537  }
538  ?>
539  <table border="0" cellpadding="0" cellspacing="0"<?echo $attrs?>>
540  <thead>
541  <tr>
542 <?php
543  $first = true;
544 
545  foreach($this->columns as $column)
546  {
547  if ($column->exportOnly) continue;
548 
549  $attrs = "";
550  $cssClass = "";
551 
552  if (!$column->sortable)
553  {
554  $cssClass = trim($cssClass." nosort");
555  }
556 
557  if ($cssClass)
558  {
559  $attrs .= " class='$cssClass'";
560  }
561 
562  if (preg_match("/^\\width:.*?\\d{1,3}px|width:.*?\\d{1,3}%/", $column->style, $matches))
563  {
564  $attrs .= " style='{$matches[0]}'";
565  }
566 
567  if ($column->sortFormat) $attrs .= " data-sort='true'";
568 ?>
569  <th<?echo $attrs?>>
570 <?php
571 
572  if ($first)
573  {
574  if ($this->excelFile)
575  {
576  $qs = $this->getExcelLink();
577  }
578 
579  if ($this->excelFile && !$this->menu && !$this->hideExcelIcon)
580  {
581 ?>
582  <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>
583 <?
584  }
585  else if ($this->menu)
586  {
587  if ($this->excelFile)
588  {
589  $this->menu->command($this->id."_excel", "Save as Excel...", $qs, "/fakoli/images/msexcel_icon_small.png");
590  }
591 ?>
592  <img id="<?echo $this->id?>_menu_button" src="<?echo $this->commandMenuIcon?>" alt="Table Menu" style="border: none; display:inline-block;vertical-align: middle"/>
593 <?
594  }
595 
596  foreach($this->toolbarCallbacks as $callback)
597  {
598  echo "<div style='display: inline-block; float: left'>";
599  echo call_user_func($callback, $this);
600  echo "</div>";
601  }
602  }
603  $first = false;
604 ?>
605 <?echo $column->title?></th>
606 <?
607  }
608 ?>
609  </tr>
610  </thead>
611  <tbody<?echo $tbodyAttrs?>>
612 <?
613  foreach($this->items as $item)
614  {
615  $cl = array();
616  if($this->rowId)
617  $rowId = $this->formatRowId($item);
618 
619  if ($this->onStartRow)
620  {
621  $retval = call_user_func($this->onStartRow, $item);
622  if ($retval === false) continue; // return false to indicate row should be skipped
623  if ($retval) $cl[] = $retval; // return a string to indicate a css class for the row
624  }
625 
626  $dataAttrs = array();
627  foreach($this->tagRowCallbacks as $cb)
628  {
629  $dataAttrs = call_user_func($cb, $item, $dataAttrs);
630  }
631 
632  $rowAttrs = "";
633  foreach($dataAttrs as $name => $value)
634  {
635  $rowAttrs .= " ".$name."='".$value."'";
636  }
637 
638  foreach($this->totalCallbacks as $cb)
639  {
640  call_user_func($cb, $item);
641  }
642 
643  $onclick = "";
644 
645  if ($this->onRowClick)
646  {
647  $onclick = " onclick=\"" . $item->format($this->onRowClick) . "\" onmouseover=\"this.addClass('hover');";
648  if ($this->onRowHover) $onlick .= $item->format($this->onRowHover);
649  $onclick .=" return false;\" onmouseout=\"this.removeClass('hover'); return false;\"";
650  $cl[] = "clickable";
651  }
652 
653  $cl = implode(" ", $cl);
654  if ($cl) $cl = "class='$cl'";
655  if ($rowId) $rowId = "id='$rowId' ";
656 ?>
657  <tr <?echo $rowId?><?php echo $cl?><?echo $onclick?><?echo $rowAttrs?>>
658 <?php
659  foreach($this->columns as $column)
660  {
661  if ($column->exportOnly) continue;
662 
663  $attrs = "";
664  $cssClass = "";
665 
666  if (preg_match("/^[\\w_]*$/", $column->style))
667  {
668  $cssClass = $column->style;
669  }
670  else
671  {
672  $attrs .= " style='{$column->style}'";
673  }
674 
675  if ($cssClass)
676  {
677  $attrs .= " class='$cssClass'";
678  }
679 
680  if ($column->sortFormat) $attrs .= " data-sort='".htmlentities($item->format($column->sortFormat))."'";
681 ?>
682  <td<?echo $attrs?>><?echo $column->format($item)?></td>
683 <?php
684  }
685 ?>
686  </tr>
687 <?php
688  }
689 ?>
690  </tbody>
691 <?php
692  if ($this->onDrawFooter) call_user_func($this->onDrawFooter);
693 
694  if (count($this->footerColumns) > 0)
695  {
696 ?>
697  <tfoot>
698  <tr>
699 <?php
700  foreach($this->footerColumns as $column)
701  {
702  $attrs = "";
703  $cssClass = "";
704  if ($column->style)
705  {
706  if (preg_match("/^[\\w_]*$/", $column->style))
707  {
708  $attrs .= " class='{$column->style}'";
709  }
710  else
711  {
712  $attrs .= " style='{$column->style}'";
713  }
714  }
715 
716  if ($column->colspan > 1)
717  {
718  if (!$this->dragColumnReorder)
719  {
720  $attrs .= " colspan='{$column->colspan}'";
721  ?>
722  <td<?echo $attrs?>><?echo $column->format()?></td>
723 <?php
724  }
725  else if (preg_match("/text-align:\\s*right/i", $column->style))
726  {
727  for($i = 1; $i < $column->colspan; ++$i)
728  {
729  echo "<td>&nbsp;</td>";
730  }
731 ?>
732 <td<?echo $attrs?>><?echo $column->format()?></td>
733 <?
734  }
735  else
736  {
737 ?>
738 <td<?echo $attrs?>><?echo $column->format()?></td>
739 <?
740  for($i = 1; $i < $column->colspan; ++$i)
741  {
742  echo "<td>&nbsp;</td>";
743  }
744  }
745  }
746  else
747  {
748 ?>
749 <td<?echo $attrs?>><?echo $column->format()?></td>
750 <?
751  }
752  }
753 ?>
754  </tr>
755  </tfoot>
756 <?php
757  }
758 ?>
759  </table>
760 <?php
761  if ($this->scrollable) echo "</div>";
762 
763  if ($this->menu) echo $this->menu->writeMenu();
764  }
765  else
766  {
767  echo "<p><em>{$this->emptyMessage}</em></p>";
768  }
769  }
$dragText
Optional text to display above reorderable table.
Definition: data_view.inc:89
formatRowId($item)
Definition: data_view.inc:242
$cssClass
Optional CSS class to apply to the table.
Definition: data_view.inc:55
trace($msg, $lvl, $callStack=null)
Send output to the trace log.
Definition: functions.inc:959
$rowId
whether to include an id tag for each tr row
Definition: data_view.inc:79
autoPopulate($item)
Automatically build the table columns from the given DataItem.
Definition: data_view.inc:355
getExcelLink()
Get the Excel Link.
Definition: data_view.inc:344
scrollable($height=300, $resizable=true)
Definition: data_view.inc:134

◆ enableDragReorder()

DataListView::enableDragReorder (   $handler)

Turns on drag & drop item reordering for the table.

This feature disables sorting, paging and filtering for the table.

Parameters
string$handlerURL of the handler script that processes the item reordering

Definition at line 147 of file data_view.inc.

148  {
149  $this->sortable = false;
150  $this->filter = false;
151  $this->pageSize = 0;
152  $this->paginate = false;
153  $this->dragReorder = true;
154  $this->rowId = true;
155  $this->zebra = false;
156 
157  $this->reorderHandler = $handler;
158  }

◆ exportColumn()

DataListView::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.

Use this method for extended detail columns when space is constrained on the page but more details might be useful in an exported spreadsheet

Parameters
$titlethe title of the column
$formatthe formatter for the column, either as a formatting string or callback function. (For details on format template specifications, see comments above class DataItem function format.)
$sortablewhether this column is sortable
$styleany inline styles specific to this column
$typeHinthint for cell type to use when exporting to Excel
$onExportoptional callback function to format value for Excel
string$sortFormatOptional explicit format to use as the basis for sorting
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 192 of file data_view.inc.

193  {
194  $column = new DataColumn($title, $format, $sortable, $style, $typeHint, $onExport, $sortFormat);
195  $column->exportOnly = true;
196  $this->columns[] = $column;
197  return $this;
198  }
$sortable
Specifies whether to enable client-side sorting for this table.
Definition: data_view.inc:57
Represents a column in a DataListView output table.
Definition: data_column.inc:38

◆ footerText()

DataListView::footerText (   $text = "",
  $style = "",
  $colspan = 1 
)

Adds a text column to the table footer.

Parameters
$textthe text to display
$styleany CSS classes or inline styles to apply
$colspanthe colspan for the column
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 280 of file data_view.inc.

281  {
282  $this->footerColumns[] = new FooterTextColumn($text, $style, $colspan);
283  return $this;
284  }

◆ footerTotal()

DataListView::footerTotal (   $field,
  $style = "text-align: right",
  $colspan = 1,
  $typeHint = Number 
)

Sums the total for a column.

Parameters
$fieldthe field to total in the format "{field}"
$styleany CSS classes or inline styles to apply
$colspanthe colspan for the column
$typeHinttype hint for formatting the output
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 307 of file data_view.inc.

307  : right", $colspan = 1, $typeHint = Number)
308  {
309  $column = new FooterTotalColumn($field, $template = "", $style, $colspan, $typeHint);
310  $this->footerColumns[] = $column;
311  $this->totalCallbacks[] = array($column, onStartRow);
312 
313  return $this;
314  }

◆ footerValue()

DataListView::footerValue (   $callback,
  $style = "",
  $colspan = 1 
)

Adds a value column to the table footer.

Parameters
$callbackCallback function or object method used to calculate the value for this column.
$styleany CSS classes or inline styles to apply
$colspanthe colspan for the column
Returns
DataListView returns the current instance, allowing function call chaining for the column definitions.

Definition at line 293 of file data_view.inc.

294  {
295  $this->footerColumns[] = new FooterValueColumn($callback, $style, $colspan);
296  return $this;
297  }

◆ formatRowId()

DataListView::formatRowId (   $item)

Definition at line 242 of file data_view.inc.

243  {
244  if ($this->rowIdFormat)
245  {
246  return $item->format($this->rowIdFormat);
247  }
248 
249  $pk = $item->getPrimaryKey();
250  return "{$pk}_" . $item->$pk;
251  }

◆ getExcelLink()

DataListView::getExcelLink ( )

Get the Excel Link.

Definition at line 344 of file data_view.inc.

345  {
346  $qs = appendToQueryString(getFullQueryString(), "__excel={$this->id}");
347  return baseURI().$qs;
348  }
baseURI($uri=null)
Returns the base URI for the current script, with the query string removed.
Definition: functions.inc:1531
getFullQueryString($includePOST=true)
Generates a query string containing the values passed to this page.
Definition: functions.inc:1584
appendToQueryString($qs, $params)
Appends the specified parameters to the supplied query string.
Definition: functions.inc:1543

◆ getID()

DataListView::getID ( )

Implements FacetFilterable.

Definition at line 129 of file data_view.inc.

130  {
131  return $this->id;
132  }
$id
ID of the table in the output script.
Definition: data_view.inc:56

◆ scrollable()

DataListView::scrollable (   $height = 300,
  $resizable = true 
)

Definition at line 134 of file data_view.inc.

135  {
136  $this->scrollable = true;
137  $this->height = $height;
138  $this->resizable = $resizable;
139  }
scrollable($height=300, $resizable=true)
Definition: data_view.inc:134

◆ selector()

DataListView::selector (   $format = "")

Adds a selector column to the DataListView.

If no format is specified then selection is handled via a checklist box for the list objects' primary keys.

Parameters
$format(optional) format to use for the selector

Definition at line 224 of file data_view.inc.

225  {
226  if (!$format && count($this->items))
227  {
228  $pk = $this->items[0]->primary_key;
229  $format = "<input type='checkbox' class='checkbox' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
230  }
231 
232  if($format == "radio" && count($this->items) ){
233  $pk = $this->items[0]->primary_key;
234  $format = "<input type='radio' class='radio' name='{$pk}[]' id='{$pk}_{{$pk}}' value='{{$pk}}'/>";
235  }
236 
237  $this->column("&nbsp;", $format, false, "text-align: center");
238  $this->selectable = true;
239  return $this;
240  }
column($title, $format, $sortable=false, $style=null, $typeHint=null, $onExport=null, $sortFormat=null)
Adds a column definition to the DataListView.
Definition: data_view.inc:172

◆ setColumnOrder()

DataListView::setColumnOrder (   $order)

Override the column order.

Parameters
array$orderAn array of column titles in the order they are to be displayed

Definition at line 204 of file data_view.inc.

205  {
206  $columnsByTitle = reindexList($this->columns, "title");
207  $columns = array();
208  foreach($order as $title)
209  {
210  if (array_key_exists($title, $columnsByTitle))
211  {
212  $columns[] = $columnsByTitle[$title];
213  }
214  }
215 
216  $this->columns = $columns;
217  }
reindexList($list, $field, $autoPromote=true)
Reindex an indexed or grouped query result by a different field.
Definition: data_item.inc:1799
$columns
The column definitions for the table.
Definition: data_view.inc:53

◆ setID()

DataListView::setID (   $id = null)

Sets the client-side ID for this DataListView.

Parameters
$idthe ID to use. Passing in null will generate a random ID string.

Definition at line 320 of file data_view.inc.

321  {
322  if ($this->id) return;
323  if ($id)
324  {
325  $this->id = $id;
326  return;
327  }
328 
329  $this->id = makeRandomString(6);
330  }
$id
ID of the table in the output script.
Definition: data_view.inc:56
makeRandomString($len)
Creates a randomized string of characters.
Definition: functions.inc:1675

◆ writeExcelFile()

DataListView::writeExcelFile (   $file)

Writes the data table out as an Excel File.

The file is output with an 'attachment' disposition, which will prompt a save dialog in the client browser.

Parameters
$filethe name of the file to be output.
Returns
Does not return - exits script on completion to prevent corruption of the output file.

Definition at line 778 of file data_view.inc.

779  {
780  $x = ExcelFileWriter::create($file);
781 
782  $c = 0;
783  foreach($this->columns as $column)
784  {
785  $x->writeHeading(0, $c, stripHTMLTags(stripHTML($column->title)));
786  ++$c;
787  }
788 
789  $r = 1;
790  foreach($this->items as $item)
791  {
792  $c = 0;
793  if ($this->onStartRow)
794  {
795  $retval = call_user_func($this->onStartRow, $item);
796  if ($retval === false) continue;
797  }
798 
799  foreach($this->totalCallbacks as $cb)
800  {
801  call_user_func($cb, $item);
802  }
803 
804  foreach($this->columns as $column)
805  {
806  if($column->onExport)
807  $val = call_user_func($column->onExport, $item, $column);
808  else
809  $val = $column->format($item);
810 
811  switch($column->typeHint)
812  {
813  case String:
814 
815  $x->writeText($r, $c, stripHTMLTags(stripHTML($val)));
816  break;
817 
818  case Number:
819 
820  $x->writeNumber($r, $c, $val);
821  break;
822 
823  case Currency:
824 
825  $val = str_replace(array("$", ","), array("", ""), $val);
826  $x->writeCurrency($r, $c, $val);
827  break;
828 
829  case Percentage:
830 
831  $x->writePercentage($r, $c, $val);
832  break;
833 
834  default:
835 
836  /* JDG 5/11/10 currency export fix */
837  if (preg_match("/^[\\d\\,\\.\\$]+$/", $val))
838  {
839  $val = str_replace(array("$", ","), array("", ""), $val);
840  $x->writeNumber($r, $c, $val);
841  }
842  else
843  {
844  // No HTML required in Excel output
845  $x->writeText($r, $c, stripHTMLTags(stripHTML($val)));
846  }
847  }
848 
849  ++$c;
850  }
851  ++$r;
852  }
853 
854  $c = 0;
855 
856  if ($this->footerColumns)
857  {
858  foreach($this->footerColumns as $column)
859  {
860  $val = $column->format();
861  /* JDG 5/11/10 currency export fix */
862  if (preg_match("/^[\\d\\,\\.]+$/", $val))
863  {
864  $val = str_replace(",", "", $val);
865  $x->writeFooterNumber($r, $c, $val);
866  }
867  else
868  {
869  // No HTML required in Excel output
870  $x->writeFooter($r, $c, stripHTMLTags(stripHTML($val)));
871  }
872  $c += $column->colspan;
873  }
874  }
875 
876  $x->send();
877 
878  session_write_close();
879  exit();
880  }
stripHTMLTags($text)
Removes all HTML tags from the specified string.
Definition: functions.inc:1440
static create($filename)
Definition: excel.inc:45
stripHTML($text)
Definition: functions.inc:809

◆ writeScript()

DataListView::writeScript ( )

Write the Javascript to implement the table output.

Returns
string containing the required Javascript.

Definition at line 372 of file data_view.inc.

373  {
374  $this->setID(); // Set to a default ID if none was specified.
375 
376  if ($_REQUEST["__column_order"])
377  {
378  $this->setColumnOrder(explode("|", $_REQUEST["__column_order"]));
379  }
380 
381  if ($this->excelFile && $_REQUEST["__excel"] == $this->id)
382  {
383  $this->writeExcelFile($this->excelFile);
384  }
385 
386  if (count($this->items) == 0) return;
387 
389  {
390  $script =
391  "\t<script type='text/javascript' src='/fakoli/js/sorting_table.js'></script>\n".
392  "\t<script type='text/javascript' src='/fakoli/js/paginating_table.js'></script>\n".
393  "\t<script type='text/javascript' src='/fakoli/js/filtering_table.js'></script>\n".
394  "\t<script type='text/javascript' src='/fakoli/js/scrolling_table.js'></script>\n";
395 
397  }
398 
399  $constructor = "";
400  if (!$this->sortable && $this->pageSize <= 0 && !$this->filter && !$this->dragReorder)
401  {
402  return "";
403  }
404 
405  $zebra = $this->zebra ? "true" : "false";
406 
407  if ($this->pageSize > 0 AND $this->paginate)
408  {
409  $constructor = "\n\t\tvar {$this->id}_paginator = new PaginatingTable('{$this->id}', '{$this->id}_paginator', {per_page: {$this->pageSize}, zebra: $zebra});";
410  }
411  else
412  {
413  $constructor = "\n\t\tvar {$this->id}_paginator = false;";
414  }
415 
416  if ($this->filter !== false)
417  {
418  $constructor .= "\n\t\tvar {$this->id}_filter = new FilteringTable('{$this->id}', '{$this->id}_filter', {column: {$this->filter}, paginator: {$this->id}_paginator});";
419  }
420  else
421  {
422  $constructor .= "\n\t\tvar {$this->id}_filter = false;";
423  }
424 
425  if ($this->sortable)
426  {
427  $constructor .= "\n\t\tvar {$this->id}_sort = new SortingTable('{$this->id}', { paginator: {$this->id}_paginator, filter: {$this->id}_filter, zebra: $zebra});";
428  }
429 
430  if ($this->selectable)
431  {
432  $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; };";
433  }
434 
435  if ($this->scrollable)
436  {
437  $constructor .= "\n\t\tnew ScrollingTable('{$this->id}');";
438  }
439 
440  if ($constructor || $this->dragReorder || $this->dragColumnReorder)
441  {
442  $script .= "\t<script type='text/javascript'>\n\twindow.addEvent('domready', function()\n{";
443  $script .= $constructor;
444 
445  if ($this->dragReorder)
446  {
447  $script .= "\n\t\tnew DraggableTable('#{$this->id} tbody', '{$this->reorderHandler}', '{$this->items[0]->primary_key}');";
448  }
449 
450  if ($this->dragColumnReorder)
451  {
452  $options = ($this->columnReorderCallback) ? ", {onColumnsReordered: $this->columnReorderCallback}" : "";
453  $script .= "\n\tnew DraggableColumnTable('{$this->id}'$options);";
454  }
455 
456  $script .= "\n\t});\n\t</script>\n";
457  }
458 
459 
460  if ($this->menu) $script .= $this->menu->writeScript();
461  return $script;
462  }
static $includesWritten
Definition: data_view.inc:96
writeExcelFile($file)
Writes the data table out as an Excel File.
Definition: data_view.inc:778
setColumnOrder($order)
Override the column order.
Definition: data_view.inc:204
setID($id=null)
Sets the client-side ID for this DataListView.
Definition: data_view.inc:320
scrollable($height=300, $resizable=true)
Definition: data_view.inc:134
$columnReorderCallback
Javascript callback function that is triggered when columns are reordered.
Definition: data_view.inc:84
$zebra
Specifies whether alternate rows in the table should be striped.
Definition: data_view.inc:69

Member Data Documentation

◆ $columnReorderCallback

DataListView::$columnReorderCallback = null

Javascript callback function that is triggered when columns are reordered.

Definition at line 84 of file data_view.inc.

◆ $columns

DataListView::$columns

The column definitions for the table.

Definition at line 53 of file data_view.inc.

◆ $commandMenuIcon

DataListView::$commandMenuIcon = "/fakoli/images/data_view_menu.png"

Icon to use for the command menu dropdown.

Definition at line 94 of file data_view.inc.

◆ $cssClass

DataListView::$cssClass

Optional CSS class to apply to the table.

Definition at line 55 of file data_view.inc.

◆ $cssStyle

DataListView::$cssStyle

Optional additional inline styles to apply to the table.

Definition at line 59 of file data_view.inc.

◆ $dragColumnReorder

DataListView::$dragColumnReorder = false

Enable drag & drop column reordering and show/hide capabilities.

Definition at line 83 of file data_view.inc.

◆ $dragReorder

DataListView::$dragReorder = false

Enabled drag & drop reordering.

Definition at line 81 of file data_view.inc.

◆ $dragText

DataListView::$dragText = ""

Optional text to display above reorderable table.

Definition at line 89 of file data_view.inc.

◆ $emptyMessage

DataListView::$emptyMessage

Message to display when no items are present in the data set.

Definition at line 60 of file data_view.inc.

◆ $excelFile

DataListView::$excelFile

Filename for automatic Excel export.

Definition at line 66 of file data_view.inc.

◆ $filter

DataListView::$filter

Specifies whether to enable client-side filtering for this table.

Definition at line 65 of file data_view.inc.

◆ $footerColumns

DataListView::$footerColumns

The footer column definitions for the table.

Definition at line 54 of file data_view.inc.

◆ $height

DataListView::$height

Definition at line 73 of file data_view.inc.

◆ $hideExcelIcon

DataListView::$hideExcelIcon = false

Suppress the automatic Excel icon if you want an external link.

Definition at line 85 of file data_view.inc.

◆ $id

DataListView::$id

ID of the table in the output script.

Definition at line 56 of file data_view.inc.

◆ $includesWritten

DataListView::$includesWritten = false
static

Definition at line 96 of file data_view.inc.

◆ $menu

DataListView::$menu = null

Context menu for selection-based operations.

Definition at line 93 of file data_view.inc.

◆ $onDrawfooter

DataListView::$onDrawfooter

Callback hook that gets called after all rows have been drawn.

Definition at line 62 of file data_view.inc.

◆ $onRowClick

DataListView::$onRowClick = null

Javascript callback function that is triggered with a row is clicked.

Definition at line 86 of file data_view.inc.

◆ $onRowHover

DataListView::$onRowHover = null

Javascript callback function that is triggered with a row is hovered over.

Definition at line 87 of file data_view.inc.

◆ $onStartRow

DataListView::$onStartRow

Callback hook that gets called at the start of each row.

Definition at line 61 of file data_view.inc.

◆ $pageSize

DataListView::$pageSize

Specifies the number of items per page - set to zero for unpaginated.

Definition at line 58 of file data_view.inc.

◆ $paginate

DataListView::$paginate = true

Specifies whether table should be paginated (false for view only pages)

Definition at line 67 of file data_view.inc.

◆ $reorderHandler

DataListView::$reorderHandler = null

Handler script that implements reordering records.

Definition at line 82 of file data_view.inc.

◆ $resizable

DataListView::$resizable = true

Definition at line 75 of file data_view.inc.

◆ $rowId

DataListView::$rowId = false

whether to include an id tag for each tr row

Definition at line 79 of file data_view.inc.

◆ $rowIdFormat

DataListView::$rowIdFormat = null

Optionally specify a custom row ID format.

Definition at line 80 of file data_view.inc.

◆ $scrollable

DataListView::$scrollable = false

Definition at line 74 of file data_view.inc.

◆ $selectable

DataListView::$selectable = false

Whether the table provides a selection mechanism.

Definition at line 92 of file data_view.inc.

◆ $sortable

DataListView::$sortable

Specifies whether to enable client-side sorting for this table.

Definition at line 57 of file data_view.inc.

◆ $summary

DataListView::$summary

Human-readable summary of the information contained in the table (for usability/accessiblity purposes)

Definition at line 68 of file data_view.inc.

◆ $tagRowCallbacks

DataListView::$tagRowCallbacks

Array of callbacks for adding extra attributes to each row.

Definition at line 63 of file data_view.inc.

◆ $toolbarCallbacks

DataListView::$toolbarCallbacks = array()

Override this callback to add toolbar links into the first header cell.

Definition at line 95 of file data_view.inc.

◆ $totalCallbacks

DataListView::$totalCallbacks

Array of callbacks for totalling columns.

Definition at line 64 of file data_view.inc.

◆ $zebra

DataListView::$zebra

Specifies whether alternate rows in the table should be striped.

Definition at line 69 of file data_view.inc.


The documentation for this class was generated from the following file: