diff --git a/README.md b/README.md index 34c5c97..83b518e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ It's similar to Microsoft's WebForms with a great layout by default (like DevExp ## Available components * Table * Card -* Breadcumb +* Breadcrumb ## Examples @@ -22,11 +22,29 @@ $table->setDataSource($employees); $table->setCustomCaptions(array("Name", "Surname", "Date of Birth", "Social Security Number")); //not required. If not specified it'll use objects' property names +$table->addColumn("Extra"); + +$table->onValueDisplaying("onValueDisplaying"); + $table->setStripedRows(true); $table->setBordered(true); $table->setHoverAnimation(true); $table->draw(); + +function onValueDisplaying($caption, &$value, $row){ + if($caption == "ssn"){ + if($row["ssn"] != "12345"){ + $value = "SSN not shown for privacy reasons"; + } + else{ + $value = $row["name"] . " " . $row["surname"] . " agreed to share their ssn (12345)" ; + } + } + else if($caption == "Extra"){ + $value = "This column did not exist in the datasource"; + } +} ``` produces the following output diff --git a/phpxpress/examples/demoTable.jpg b/phpxpress/examples/demoTable.jpg index c70fbb4..23c1b15 100644 Binary files a/phpxpress/examples/demoTable.jpg and b/phpxpress/examples/demoTable.jpg differ diff --git a/phpxpress/examples/table.php b/phpxpress/examples/table.php index 9b32c0c..85af30b 100644 --- a/phpxpress/examples/table.php +++ b/phpxpress/examples/table.php @@ -37,17 +37,28 @@ $table = new Table; $table->setDataSource($employees); $table->setCustomCaptions(array("Name", "Surname", "Date of Birth", "Social Security Number")); + + $table->addColumn("Extra"); + + $table->onValueDisplaying("onValueDisplaying"); + $table->setStripedRows(true); $table->setBordered(true); $table->setHoverAnimation(true); - $table->onValueDisplaying("onValueDisplaying"); // event - $table->draw(); - function onValueDisplaying($caption, &$value){ + function onValueDisplaying($caption, &$value, $row){ if($caption == "ssn"){ - $value = "SSN not shown for privacy reasons"; + if($row["ssn"] != "12345"){ + $value = "SSN not shown for privacy reasons"; + } + else{ + $value = $row["name"] . " " . $row["surname"] . " agreed to share their ssn (12345)" ; + } + } + else if($caption == "Extra"){ + $value = "This column did not exist in the datasource"; } } diff --git a/phpxpress/phpxpress/table.php b/phpxpress/phpxpress/table.php index 91fb0d9..9521836 100644 --- a/phpxpress/phpxpress/table.php +++ b/phpxpress/phpxpress/table.php @@ -46,7 +46,7 @@ foreach ($obj as $name => $value) { if(isset( $this -> onValueDisplayingFunctionName)){ - call_user_func_array($this -> onValueDisplayingFunctionName , array($name, &$value)); + call_user_func_array($this -> onValueDisplayingFunctionName , array($name, &$value, (array)$obj)); } echo '' . $value . ''; @@ -82,17 +82,41 @@ throw new LengthException('Number of provided captions not matching the datasource ones.'); } + /* + ** if you use addColumn() either + ** 1) you do not use any dataSource + ** 2) you set the dataSource prior to call this method (otherwise it won't be correctly shown) + */ + function addColumn($captionName){ + + if(isset($this->columnCaptions)){ + array_push($this->columnCaptions , $captionName); + } + else{ + $this->columnCaptions = array($captionName); + } + + // Add this property to every object/array of the dataSource + if(isset($this->dataSource)){ + foreach($this->dataSource as $obj){ + $obj->{$captionName} = null; + } + } + + } + /* ** 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){...} + ** function myFunction($caption, &$value, $row){...} ** ** You can change "caption" and "value" to whichever name you want. ** - ** caption: the ACTUAL fieldname of the dataSource whose value belong + ** caption: the ACTUAL fieldname of the dataSource whose value belongs to ** value: the value you want to display. + ** row: an associative array representing the row being processed */ function onValueDisplaying($functionName){ if(!is_callable($functionName))