mirror of https://github.com/xfarrow/phpxpress.git
added event management
This commit is contained in:
parent
83d6900995
commit
d0a106f6a7
|
@ -40,8 +40,17 @@
|
|||
$table->setStripedRows(true);
|
||||
$table->setBordered(true);
|
||||
$table->setHoverAnimation(true);
|
||||
|
||||
$table->onValueDisplaying("onValueDisplaying"); // event
|
||||
|
||||
$table->draw();
|
||||
|
||||
function onValueDisplaying($caption, &$value){
|
||||
if($caption == "ssn"){
|
||||
$value = "SSN not shown for privacy reasons";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -2,9 +2,14 @@
|
|||
include "include.php";
|
||||
|
||||
class Table{
|
||||
// Structure
|
||||
private $dataSource;
|
||||
private $columnCaptions;
|
||||
|
||||
// Events
|
||||
private $onValueDisplayingFunctionName;
|
||||
|
||||
// Layout
|
||||
private $darkTheme = false;
|
||||
private $stripedRows = false;
|
||||
private $bordered = false;
|
||||
|
@ -39,7 +44,12 @@
|
|||
foreach($this->dataSource as $obj){
|
||||
echo '<tr>';
|
||||
foreach ($obj as $name => $value) {
|
||||
|
||||
if(isset( $this -> onValueDisplayingFunctionName)){
|
||||
call_user_func_array($this -> onValueDisplayingFunctionName , array($name, &$value));
|
||||
}
|
||||
echo '<td>' . $value . '</td>';
|
||||
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
|
@ -72,6 +82,25 @@
|
|||
throw new LengthException('Number of provided captions not matching the datasource ones.');
|
||||
}
|
||||
|
||||
/*
|
||||
** The Event "onValueDisplaying" gets fired just before the displaying of a value within
|
||||
** a table body, so you can display your own value if you want to.
|
||||
** The function you have to provide must have this signature:
|
||||
**
|
||||
** function myFunction($caption, &$value){...}
|
||||
**
|
||||
** You can change "caption" and "value" to whichever name you want.
|
||||
**
|
||||
** caption: the ACTUAL fieldname of the dataSource whose value belong
|
||||
** value: the value you want to display.
|
||||
*/
|
||||
function onValueDisplaying($functionName){
|
||||
if(!is_callable($functionName))
|
||||
throw new InvalidArgumentException("Couldn't call $functionName. You must provide the name of a function.");
|
||||
|
||||
$this -> onValueDisplayingFunctionName = $functionName;
|
||||
}
|
||||
|
||||
function setDarkTheme($bool){
|
||||
if(!is_bool($bool)){
|
||||
throw new InvalidArgumentException('Parameter must be a boolean.');
|
||||
|
|
Loading…
Reference in New Issue