QDataGrid and DataBinder
Hello All,
Please kindly assist me look into this:
I have a QDataGrid I use for Reporting. I also have report spans (Today's Report, This week's report, This Month's Report, This Year, and Custom). The idea is that i change the data in the Datagrid to match the selected span for the report.
However, I noticed that whenever i switch to another report span, the OrderByClause and LimitClause of the previous data binded are carried over to this one so that I get WIERD paginations link "210-230 of 87".
I used the setclauses statement before I execute query array as follows:
protected function setDatagridClauses(){
// Setup the $objClauses Array
$objClauses = array();
// If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
// the OrderByClause to the $objClauses array
if ($objClause = $this->dtgCertReport->OrderByClause)
array_push($objClauses, $objClause);
// Add the LimitClause information, as well
if ($objClause = $this->dtgCertReport->LimitClause)
array_push($objClauses, $objClause);
return $objClauses;
}My QUESTION:
How do I clear the previous OrderByClauses and LimitClauses before I execute the QueryArray statement so I don't carry over unwanted behaviours as described above.
Thank you so much.

Set the appropriate properties on the data grid when you want them to change.
So for example, when switching spans, you probably also want to set $dataGrid->PageNumber = 1; and $dataGrid->SortColumnIndex = 1;
hope this example can help you - To test the possibility to add a search box I simply modified a Qpanel from draft. This let me choose Qcubed to rapid develop user friendly applications.
added blocks have comment //Magia
magic is done by
$this->dtgRisorses->SetDataBinder('RisorseDataBinder', $this);
in __construct(.......) function
by
RisorseDataBinder() function
and by
// Magia 2009 set page 1
$this->dtgRisorses->PageNumber = 1;
// fine magia set page 1
$this->dtgRisorses->Refresh();
at the end of
txtCognomenomeSearch_Click(....) function
Sorry for italian language in some comments
Gianni
<?php
/**
* This is the abstract Panel class for the List All functionality
* of the Risorse class. This code-generated class
* contains a datagrid to display an HTML page that can
* list a collection of Risorse objects. It includes
* functionality to perform pagination and sorting on columns.
*
* To take advantage of some (or all) of these control objects, you
* must create a new QPanel which extends this RisorseListPanelBase
* class.
*
* Any and all changes to this file will be overwritten with any subsequent re-
* code generation.
*
* @package My Application
* @subpackage Drafts
*
*/
class RisorseListPanel extends QPanel {
// Local instance of the Meta DataGrid to list Risorses
public $dtgRisorses;
// Other public QControls in this panel
public $btnCreateNew;
public $pxyEdit;
// Callback Method Names
protected $strSetEditPanelMethod;
protected $strCloseEditPanelMethod;
// Magia 2009 - search field
protected $strCognomenomeToFind;
public $lblMessage;
public $lblCognomenomeSearch_override;
public $txtCognomenomeSearch;
public $lblRisRic; //Label ricerca risorsa
public $txtRisRic; //Input ricerca risorsa
public $strRisToFind; //Risorsa da ricercare
public function __construct($objParentObject, $strSetEditPanelMethod, $strCloseEditPanelMethod, $strControlId = null) {
// Call the Parent
try {
parent::__construct($objParentObject, $strControlId);
} catch (QCallerException $objExc) {
$objExc->IncrementOffset();
throw $objExc;
}
// Record Method Callbacks
$this->strSetEditPanelMethod = $strSetEditPanelMethod;
$this->strCloseEditPanelMethod = $strCloseEditPanelMethod;
// Setup the Template
$this->Template = 'RisorseListPanel.tpl.php';
// Magia 2009 - search field
// messages - used now (e.g. Name not found ...etc)
$this->lblMessage= new Qlabel($this);
// search field text override so I can put longer text
$this->lblCognomenomeSearch_override= new Qlabel($this);
$this->lblCognomenomeSearch_override->Text = 'cerca per Cognomenome (usa % per tutti):';
$this->txtCognomenomeSearch = new QTextBox($this);
//$this->txtCognomenomeSearch->Width = "80";
$this->txtCognomenomeSearch->AddAction(new QEnterKeyEvent(), new QServerControlAction($this,'txtCognomenomeSearch_Click'));
// magia 2009 textboxlabel not used I am noy abel to change his dimensin use a label named xx_override
//$this->txtCognomenomeSearch->Name = 'search by targa (use % to global):';
// fine Magia
// Instantiate the Meta DataGrid
$this->dtgRisorses = new RisorseDataGrid($this);
// Style the DataGrid (if desired)
$this->dtgRisorses->CssClass = 'datagrid';
$this->dtgRisorses->AlternateRowStyle->CssClass = 'alternate';
// magia 2009 - inserisci qui il data binder
// in modo che il refresh possa avvenire
//
$this->dtgRisorses->SetDataBinder('RisorseDataBinder', $this);
// magia fine data binder
// Add Pagination (if desired)
$this->dtgRisorses->Paginator = new QPaginator($this->dtgRisorses);
$this->dtgRisorses->ItemsPerPage = 10;
// Use the MetaDataGrid functionality to add Columns for this datagrid
// Create an Edit Column
$this->pxyEdit = new QControlProxy($this);
$this->pxyEdit->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'pxyEdit_Click'));
$this->dtgRisorses->MetaAddEditProxyColumn($this->pxyEdit, 'Edit', 'Edit');
// Create the Other Columns (note that you can use strings for risorse's properties, or you
// can traverse down QQN::risorse() to display fields that are down the hierarchy)
$this->dtgRisorses->MetaAddColumn('Id');
//$this->dtgRisorses->MetaAddColumn('Cognomenome');
$colCn=$this->dtgRisorses->MetaAddColumn('Cognomenome');
$colCn->Name = 'Descrizione';
//$this->dtgRisorses->MetaAddColumn('CodiceFiscale');
$colCf=$this->dtgRisorses->MetaAddColumn('CodiceFiscale');
$colCf->Name = 'Cod. Fiscale';
// magia 2009 spostato
//$this->dtgRisorses->MetaAddColumn('Note');
$colDi=$this->dtgRisorses->MetaAddColumn('DataIniziorapporto');
$colDi->Name = 'In. Rapporto Gruppo';
$colDf=$this->dtgRisorses->MetaAddColumn('DataFinerapporto');
$colDf->Name = 'Fn. Rapporto Gruppo';
//$this->dtgRisorses->MetaAddColumn('DataIniziorapporto');
//$this->dtgRisorses->MetaAddColumn('DataFinerapporto');
// magia 2009 usa type da risorsetipo_type
//$this->dtgRisorses->MetaAddColumn('TipoRisorsa');
$colTr=$this->dtgRisorses->MetaAddTypeColumn('TipoRisorsa', 'RisorsetipoType');
$colTr->Name = 'Tipo Risorsa';
//$this->dtgRisorses->MetaAddTypeColumn('TipoRisorsa', 'RisorsetipoType');
// magia fine
//$this->dtgRisorses->MetaAddColumn('Descrizione');
//$this->dtgRisorses->MetaAddColumn('Qualifica');
$this->dtgRisorses->MetaAddColumn('Matricola');
$this->dtgRisorses->MetaAddColumn('InRapporto');
$this->dtgRisorses->MetaAddColumn('FnRapporto');
$this->dtgRisorses->MetaAddColumn('Mail');
//$this->dtgRisorses->MetaAddColumn('Direzione');
//$this->dtgRisorses->MetaAddColumn('AliasDirezione');
//$this->dtgRisorses->MetaAddColumn('InsUser');
$this->dtgRisorses->MetaAddColumn('DataIns');
$this->dtgRisorses->MetaAddColumn('Note');
//$this->dtgRisorses->MetaAddColumn('AzLast');
//$this->dtgRisorses->MetaAddColumn('AzLastAlias');
//$this->dtgRisorses->MetaAddColumn('SedeLast');
//$this->dtgRisorses->MetaAddColumn('CdCLast');
//$this->dtgRisorses->MetaAddColumn('TestoCdCLast');
// magia 2009 lesson - colonna iniziale di ordinamento
// - direction 0 ascend 1 discend
// set order on column 2 - cognomenome
$this->dtgRisorses->SortColumnIndex = 2;
$this->dtgRisorses->SortDirection = 0;
// Setup the Create New button
$this->btnCreateNew = new QButton($this);
$this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('Risorse');
$this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
}
public function pxyEdit_Click($strFormId, $strControlId, $strParameter) {
$strParameterArray = explode(',', $strParameter);
$objEditPanel = new RisorseEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0]);
$strMethodName = $this->strSetEditPanelMethod;
$this->objForm->$strMethodName($objEditPanel);
}
public function btnCreateNew_Click($strFormId, $strControlId, $strParameter) {
$objEditPanel = new RisorseEditPanel($this, $this->strCloseEditPanelMethod, null);
$strMethodName = $this->strSetEditPanelMethod;
$this->objForm->$strMethodName($objEditPanel);
}
//Magia 2009
// function addedd to handle search
public function txtCognomenomeSearch_Click($strFormId, $strControlID, $strParameter)
{
$this->lblMessage->Text = '';
$this->strCognomenomeToFind = $this->txtCognomenomeSearch->Text;
// magia 2009 controllo not found
// devo mettere qui il controllo
$total = 0;
if($this->strCognomenomeToFind)
{
$total = Risorse::QueryCount(QQ::Like(QQN::Risorse()->Cognomenome, $this->txtCognomenomeSearch->Text));
if ($total ==0) {
$this->lblMessage->Text = 'risorsa non trovata - le visualizzo tutte' ;
}
}
// fine magia 2009 controllo not found
// Magia 2009 set page 1
$this->dtgRisorses->PageNumber = 1;
// fine magia set page 1
$this->dtgRisorses->Refresh();
}
public function RisorseDataBinder()
{
$aryClauses = array();
$aryConditions = array();
$objConditions = null;
if ($objClause = $this->dtgRisorses->OrderByClause)
array_push($aryClauses, $objClause);
if ($objClause = $this->dtgRisorses->LimitClause)
array_push($aryClauses, $objClause);
$aryCognomenomes = array();
//$this->strCognomenomeToFind = $this->txtCognomenomeSearch->Text . '%';
if($this->strCognomenomeToFind)
{
//$aryCognomenomes = Risorse::QueryArray(QQ::Like(QQN::Risorse()->Cognomenome, $this->txtCognomenomeSearch->Text));
$aryCognomenomes = Risorse::QueryArray(QQ::Like(QQN::Risorse()->Cognomenome, $this->strCognomenomeToFind));
// print_r($aryCognomenomes);
}
if(count($aryCognomenomes) > 0)
$objCondition = QQ::Like (QQN::Risorse()->Cognomenome, $this->txtCognomenomeSearch->Text);
else
$objCondition = QQ::All();
$this->dtgRisorses->TotalItemCount = Risorse::QueryCount($objCondition);
//$this->dtgRisorses->TotalItemCount = count($aryCognomenomes);
$aryRisorse = Risorse::QueryArray($objCondition, $aryClauses );
$this->dtgRisorses->DataSource = $aryRisorse;
}
}
?>