column not ordered with calculated field
Archived from the Xataface Users forum.
avicet — Wed Jul 11, 2007 8:47 am
Hi,
Colums in list tab are not well ordered with calculated fields, hereafter a little patch to solve the problem (may it should be helpful for somebody) :
fix are in Dataface/ResultList.php :
Add
- Code: Select all
- `foreach ($grafted_fieldnames as $field){
if ( $grafted_fields[$field][‘visibility’][‘list’] != ‘visible’) continue;
$this->_columns[] = $field;
// AVT - new col
$this->avt_OrderColumns($tablename);
}
$this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $query);`
And add the function
- Code: Select all
- `//——————————————————————
function avt_OrderColumns() {function sortOrder($a, $b) {
return($a[‘order’]-$b[‘order’]);
}$fields =& $this->_table->fields();
$gfields =& $this->_table->graftedFields();
$list = array();
foreach ($this->_columns as $fid) {
$field[‘id’] = $fid;
if (isset($fields[$fid])) $field[‘order’] = $fields[$fid][‘order’];
else $field[‘order’] = $gfields[$fid][‘order’];
$list[] = $field;
}
usort($list, ‘sortOrder’);
$line = ‘’;
unset($this->_columns);
foreach ($list as $field) {
$this->_columns[] = $field[‘id’];
}
}`
Markus — Wed Jul 11, 2007 10:24 am
Hi Alain,
thank you for the code. I added the function avt_OderColumns() at the end of my ResultList.php
Where exactly do I have to put the first piece of code? I tried it but got an error message like that:
Fatal error: Cannot redeclare sortorder() (previously declared in /kunden/116287_10407/webseiten/dataface/Dataface/ResultList.php:361) in /kunden/116287_10407/webseiten/dataface/Dataface/ResultList.php on line 361
So I think I’ve maybe done something wrong.
In my ResultList.php from line 75 until line 84 I found:
foreach ($grafted_fieldnames as $field){
if ( $grafted_fields[$field][‘visibility’][‘list’] != ‘visible’) continue;
$this->_columns[] = $field;
}
}
$this->_resultSet =& Dataface_QueryTool::loadResult($tablename, $db, $query);
}
So my question is, do I have to replace this code with your code or where does your code go?
Thank you so far
Markus
avicet — Wed Jul 11, 2007 12:12 pm
Hi markus,
I thought sortOrder function declared in avt_OrderColumns had a local scope. that’s not the case and this is problem for you because you already have a function whose name is sortOrder
You could rename my function sortOrder with avt_sortOrder for example and that’s all (don’t forget to subsitute the 2 occurences of sortOrder)
alain