variable css in qDataGrid / qDataGridColumn

thread: 5 messages  |  last: a year ago  |  started: monday, july 26, 2010, 9:31 am pdt


#1  |  tracya
Monday, July 26, 2010, 9:31 AM PDT

I'm looking to highlight certain results in red - not based on Alternate Row styles, but based on the data contained in a column.  I can highlight just the column, or the whole row.  

I have an array of objects - each object has a riskLevel.


This adds the column:

$this->dtgDataGrid->AddColumn(new QDataGridColumn('Risk Level', '<?= $_ITEM->riskLevel ?>', 'HtmlEntities=false'));



This styles all <td> in this column in the “warning” style:

$this->dtgDataGrid->AddColumn(new QDataGridColumn('Risk Level', '<?= $_ITEM->riskLevel ?>', 'CssClass=warning', 'HtmlEntities=false'));


I'd want a variable CssClass - maybe something like:

$this->dtgDataGrid->AddColumn(new QDataGridColumn('Risk Level', '<?= $_ITEM->riskLevel ?>', 'CssClass= <?= fnGetClassFromRiskLevel($_ITEM->riskLevel) ?>', 'HtmlEntities=false'));

or like this:

$this->dtgDataGrid->AddColumn(new QDataGridColumn('Risk Level', '<?= $_ITEM->riskLevel ?>', 'CssClass= <?= $_ITEM->riskStyle ?>', 'HtmlEntities=false'));

Can you think of a better approach, as this doesn't seem to work?

Thanks for the advice!

#2  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Monday, July 26, 2010, 10:06 AM PDT

Have you checked out OverrideRowStyle?

It takes in the row you are wanting to override as well as the QDataGridRowStyle object.

It's best to use something like this in a RenderMethod:

    $this->dtgDataGrid->AddColumn(new QDataGridColumn('Risk Level', '<?= $_FORM->RenderRiskLevel($_ITEM); ?>'));

and then

<?php
    
public function RenderRiskLevel($objItem) {
        if (
$objItem->RiskLevel == "High") {
            
$objStyle = new QDataGridRowStyle();
            
$objStyle->CssClass 'warning';
            
$this->dtgDataGrid->OverrideRowStyle($this->dtgDataGrid->CurrentRowIndex$objStyle);
        } else {
            
$this->dtgDataGrid->OverrideRowStyle($this->dtgDataGrid->CurrentRowIndexnull);
        }

        return 
$objItem->RiskLevel;
    }
?>

Hopefully this shows you how you can use OverrideRowStyle to override the “row style” of an individual row in your datagrid.

#3  |  tracya
Monday, July 26, 2010, 12:23 PM PDT

Thank you!  

I have a feeling this is what I need - but I am having trouble referring to the right places.

I have a QForm, which contains a few QPanels, and this QDataGrid is in one of the panels.

I would like to put this function (RenderRiskLevel) at the QPanel level, but not sure how to refer to the QPanel.

http://examples.qcodo.com/examples/datagrid/variables.php gives the reference to the QForm, I've tried getting to the form, then the panel by name:

<?= $_FORM->pnlModelView->RenderRiskLevel($_ITEM) ?>

Is there a shortcut way to get to the parent panel?  (This isn't working, but not sure if it is the function or trying to refer to it).

Thanks again.



#4  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Monday, July 26, 2010, 1:33 PM PDT

Hi tracya,

The “shortcut” is:

<?=$_CONTROL->ParentControl->RenderRiskLevel($_ITEM) ?>

where $_CONTROL is datagrid itself,
the ParentControl is datagrid parent control.

Regards,
Attila

#5  |  tracya
Monday, July 26, 2010, 1:45 PM PDT

Thanks much!

I was fussing with creating a custom class extending the datagrid.  Thanks for your help.



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.