Using two table columns as a single Datagrid Column
Tue, 09/29/2009 - 09:28
Goodday All,
Please, I wish to merge two columns in a table into one single datagrid column. Is this possible and if yes how?
<strong>Details</strong>:
Assuming we have:
Table --> Biodata (ID, Name, Sex, HostelID, OffcampusID)
Note: A student may either reside in a hostel or offcampus but not both.
e.g.
ID Name Sex HostelID OffcampusID
1 Bee M 1 NULL
2 Cee M NULL 4
3 Mabel F 8 NULLNow I wish to make a QDataGrid Column called Hostel/Offcampus, so that when the grid is rendering, if the student is in the hostel (Not NULL), it shows the hostel name else if offcampus, it shows the location offcampus or just plain blank.
I await your help, Thanks.

Please view http://examples.qcu.be/assets/_core/php/examples/datagrid/variables.php for an example of merging two columns.
Thanks Vexed, I used that method already.
Now, as you would have noticed, what contributed to fullname was first and last name of which both are on the same table.
Also, it is first AND last name = fullname
In my own case, what constitutes mine is like this, either 'ANCHORAGE' OR 'OFFSHORE', one of them is usually null when the other is set. And to add to that, they are from two different tables: ANCHORAGE from tblAnchorage and OFFSHORE from tblOffshore
I have successfully worked them to appear as needed (See code below), now the task is sorting based on that column. Can you spare me ideas on sorting based on that column in ASC and DESC order?
Thanks
$this->dtgShip2shiprpts->AddColumn(new QDataGridColumn('Anchorage/Offshore', '<?= $_CONTROL->ParentControl->DisplayAnchorageOffshore($_ITEM) ?>',
array('HtmlEntities'=>false, 'HorizontalAlign'=>QHorizontalAlign::Left)));
public function DisplayAnchorageOffshore($item){
$objAnchorage = $item->RptanchorageidObject;
$objOffshore = $item->RptoffshoreidObject;
$objAO = null;
if (!is_null($objAnchorage)){
$objAO = $objAnchorage;
}
elseif (!is_null($objOffshore)) {
$objAO = $objOffshore;
}
else {
$objAO = '';
}
$strToReturn = $objAO;
return $strToReturn;
}
I don't think you can do that with QQ right now.
Maybe if you can use custom SQL within the sort clause..
Please show me how to achieve this Panda. Thanks so much.
As I said, I don't think this is possible with QQ. You would have to switch to using raw SQL and then use the DataGridColumn's SortByCommand and ReverseSortByCommand to determine how to alter it during the bind.