tags:

views:

76

answers:

1

Hi, I am trying to add a class to the tag so that I can control its attributes, particularly width.

Here is what the generated HTML looks like with class empty.

alt text alt text

As you can see, there are several tags which I would love to be able to assign a class to so that I can do the styling from an external css file, rather than doing it within the controller as it seems to be done below. Thanks.

    // Add Target Data Grid

    $this->dtgTargets = new QDataGrid($this);
    $this->dtgTargets->CellPadding = 5;
    $this->dtgTargets->CellSpacing = 5;
    $this->dtgTargets->UseAjax = true;
    $this->dtgTargets->AddColumn(new QDataGridColumn("Del", '<?= $_FORM->DeleteButton_Render($_ITEM) ?>', 'Width=10', 'HtmlEntities=false')); //add TF 11-27-08
    $this->dtgTargets->AddColumn(new QDataGridColumn('Target Account','<a href="/account_detail.php?aid=<?= str_replace(" ","_",$_ITEM->Account->Id); ?>"><?= $_ITEM->Account->Name ?></a>','HtmlEntities=false',array('OrderByClause' => QQ::OrderBy(QQN::Target()->Account->Name), 'ReverseOrderByClause' => QQ::OrderBy(QQN::Target()->Account->Name,false))));
    $this->dtgTargets->GetColumn(0)->Width = '200px';
    $this->dtgTargets->SortColumnIndex = 0;
+1  A: 

I have never used it but I think is possible. From QDataGridBase.class.php:

        protected function GetHeaderRowHtml() {
        $objHeaderStyle = $this->objRowStyle->ApplyOverride($this->objHeaderRowStyle);

        $strToReturn = sprintf("  <tr %s>\r\n", $objHeaderStyle->GetAttributes());
        $intColumnIndex = 0;
        if ($this->objColumnArray) foreach ($this->objColumnArray as $objColumn) {
            if ($objColumn->OrderByClause) {                        
                // This Column is Sortable
                if ($intColumnIndex == $this->intSortColumnIndex)
                    $strName = $this->GetHeaderSortedHtml($objColumn);
                else
                    $strName = $objColumn->Name;

                $this->strActionParameter = $intColumnIndex;

                $strToReturn .= sprintf("    <th %s><a href=\"%s\" %s%s>%s</a></th>\r\n",
                    $this->objHeaderRowStyle->GetAttributes(),
                                QApplication::$RequestUri,
                    $this->GetActionAttributes(),
                    $this->objHeaderLinkStyle->GetAttributes(),
                    $strName);
            } else
                $strToReturn .= sprintf("    <th %s>%s</th>\r\n", $this->objHeaderRowStyle->GetAttributes(), $objColumn->Name);
            $intColumnIndex++;
        }
        $strToReturn .= "  </tr>\r\n";

        return $strToReturn;
    }

The attributes are set getting them with this method:

$this->objHeaderRowStyle->GetAttributes()

GetAttributes is implemented in QBaseClass, the base class for all classes in the system.

If you try $colMyColumn->CssClass = 'class_name'; you only set the td class :-(

After studying the code I can see the QDataGridBase.class.php when the th tag is created, the style is taken from the RowStyle object that describes a row, so a td tag. I assume that this is a bug, and QDataGrid is incomplete.

Or you just use an html table in your view, or you have to improve the QDataGrid.

UPDATE:

This is the way to do it:

        $objThStyle = new QDataGridRowStyle();
    $objThStyle->CssClass = 'custom-th';
    $this->dtgArticle->HeaderRowStyle = $objThStyle;

But it is not ideal since it is applied to al th tags. QDataGridRowStyle should be set in the column object not in the datagrid.

This is a clear example why I do not like the way Qcodo renders HTML, CSS and JavaScript. Everything is an object an must be set in the controller. In the view you can do very little. Immagine how simple would be to set the class in your view in this way:

<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>...</th>
rtacconi
Yes, you're right, this is very cumbersome...thanks for checking it out.
Angela