Source for file dbgrids.inc.php
Documentation is available at dbgrids.inc.php
* This file is part of the VCL for PHP project
* Copyright (c) 2004-2007 qadram software <support@qadram.com>
* Checkout AUTHORS file for more information on the developers
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* If true, each record will show a delete link to allow the user delete that record
function getDeleteLink() { return $this->_deletelink; }
function setDeleteLink($value) { $this->_deletelink= $value; }
function defaultDeleteLink() { return ""; }
//Calls inherited constructor
parent::__construct($aowner);
* A component to show a dataset in a tabular way
class DBGrid extends CustomDBGrid
protected $_datasource=null;
function __construct($aowner=null)
//Calls inherited constructor
parent::__construct($aowner);
function dumpHeaderCode()
parent::dumpHeaderCode();
<script type="text/JavaScript">
var agree=confirm("¿Seguro que quieres borrar este registro?");
//TODO: Datasource must link with controls to update their state when the dataset changes
if ($this->_datasource!=null)
$ds=$this->_datasource->DataSet;
for ($i=0;$i<=$ds->fields->count()-1;$i++)
$fld=$ds->fields->items[$i];
$col->Title=$fld->DisplayLabel;
$this->columns->add($col);
$this->columns->add($col);
$row->values=$ds->readFieldValues();
$record_id=$row->values[0];
$row->values[]='<A onclick="return verifydelete();" HREF="'.$this->_deletelink.'&record_id='.$record_id.'">Borrar</A>';
function getFont() { return $this->readFont(); }
function setFont($value) { $this->writeFont($value); }
$this->setDataSource($this->_datasource);
function getDataSource() { return $this->_datasource; }
function setDataSource($value)
$this->_datasource=$this->fixupProperty($value);
* A component to show a dataset in a tabular way
//Publish common properties
function getVisible() { return $this->readVisible(); }
function setVisible($value) { $this->writeVisible($value); }
private $_latestheader= null;
//Calls inherited constructor
$this->ControlStyle= "csSlowRedraw=1";
//Include the RPC to handle any request
* To give permission to execute certain methods
* @param string $method Method for which we want to know the accessibility
* @param integer $defaccesibility If the method is not found, this will be returned
case "updateRow": return Accessibility_Domain;
return(parent::readAccessibility($method, $defaccessibility));
* Updates a row of the attached datasource->dataset, this method is called
* using ajax from the client
* @param array $params Array of parameters to this method
* @param object $error RPC Error object to return if anything goes wrong
$error->SetError(JsonRpcError_ParameterMismatch, "Expected 4 parameter; got " . count($params));
//Get an array with the keys and fields to change
while (list ($k,$v)= each($fieldnames))
if ((in_array($v,$keys)) || ($fieldvalues[$k]!= $origvalues[$k]))
$output[$v]= $fieldvalues[$k];
$error->SetError(- 104, 'Caught exception: '. $e->getMessage());
$error->SetError(- 103, "Datasource->Dataset->Database not assigned");
$error->SetError(- 102, "Datasource->Dataset not assigned");
$error->SetError(- 101, "Datasource not assigned");
* Dump javascript code to attach the updateRow method to the grid using ajax
function <?php echo $this->Name; ?>_rpcdatachanged(event)
modifiedRow=data.firstRow;
row=this.getRowData(modifiedRow);
orow=this.originalData[modifiedRow];
qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true);
var rpc = new qx.io.remote.Rpc();
rpc.setUrl(" <?php echo $_SERVER['PHP_SELF']; ?>");
rpc.setServiceName(" <?php echo $this->owner->Name; ?>. <?php echo $this->Name; ?>");
rpc.setCrossDomain(false);
row=obj.getRowData(result);
obj.originalData[result]=row.slice();
, "updateRow", this.ColumnNames, row, orow, modifiedRow
* Creates the DBGrid Table Model
var <?php echo $this->Name; ?>_tableModel = new qx.ui.table.SimpleTableModel();
//TODO: Datasource must link with controls to update their state when the dataset changes
//Ensure there is a valid datasource
// $this->createTableModel();
<?php echo $this->Name; ?>_tableModel.setColumns([
while(list ($fname, $value)= each($fields))
$props= $this->_datasource->DataSet->readFieldProperties($fname);
$dlabel= $props['displaylabel'][0];
<?php echo $this->Name; ?>_tableModel.ColumnNames=new Array(
while(list ($fname, $value)= each($cnames))
while (list ($k,$v)= each($rvalues))
while (list ($k,$v)= each($rvalues))
<?php echo $this->Name; ?>_tableModel.originalData=oData;
<?php echo $this->Name; ?>_tableModel.setData(rowData);
$this->_latestheader= $fields;
while(list ($fname, $value)= each($fields))
<?php echo $this->Name; ?>_tableModel.setColumnEditable( <?php echo $i; ?>, true);
function getFont() { return $this->readFont(); }
function setFont($value) { $this->writeFont($value); }
function getDataSource() { return $this->_datasource; }
function setDataSource($value)
* This event is fired whenever the contents of a cell is changed
function defaultjsOnDataChanged() { return ""; }
* This event is fired whenever the contents of a row are saved
function setjsOnRowSaved($value) { $this->_jsonrowsaved= $value; }
function defaultjsOnOnRowSaved() { return ""; }
* This event is fired whenever the active row is changed
function defaultjsOnOnRowChanged() { return ""; }
function getjsOnClick () { return $this->readjsOnClick(); }
function setjsOnClick ($value) { $this->writejsOnClick($value); }
function getjsOnDblClick () { return $this->readjsOnDblClick(); }
function setjsOnDblClick ($value) { $this->writejsOnDblClick($value); }
* Dump the common code for this control
echo " ". $this->Name. ".setBorder(qx.renderer.border.BorderPresets.getInstance().shadow);\n";
echo " ". $this->Name. ".setBackgroundColor(\"white\");\n";
echo " $this->Name.setLeft(0);\n";
echo " $this->Name.setTop(0);\n";
// echo " $this->Name.setOverflow(\"auto\");\n";
echo " $this->Name.setWidth($this->Width);\n";
echo " $this->Name.setHeight($this->Height);\n";
echo " $this->Name.getSelectionModel().setSelectionMode(qx.ui.table.SelectionModel.MULTIPLE_INTERVAL_SELECTION);\n";
$fields= $this->_latestheader;
while(list ($fname, $value)= each($fields))
$props= $this->_datasource->DataSet->readFieldProperties($fname);
$dwidth= $props['displaywidth'][0];
echo " $this->Name.getTableColumnModel().setColumnWidth($i,$dwidth);\n";
echo " var ". $this->Name. " = new qx.ui.table.Table(". $this->Name. "_tableModel);\n";
echo " ". $this->Name. "_tableModel.addEventListener(\"dataChanged\", ". $this->Name. "_rpcdatachanged, ". $this->Name. "_tableModel);\n";
echo " $this->Name.addEventListener(\"click\", $this->_jsonclick);\n";
echo " $this->Name.getSelectionModel().addEventListener(\"changeSelection\", $this->_jsonrowchanged);\n";
echo " $this->Name.addEventListener(\"dblclick\", $this->_jsondblclick);\n";
* This method is called to know the code to be executed to update the control
|