mirror of https://github.com/xfarrow/phpxpress.git
improvements
This commit is contained in:
parent
d0a106f6a7
commit
58aca67a9b
20
README.md
20
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
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 144 KiB |
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 '<td>' . $value . '</td>';
|
||||
|
||||
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue