Calculate the value of a field "b" in GetFormatter function of a field "a"
Calculate the value of a field "b" in GetFormatter function of a field "a"
jgcaudet
Posts: 82Questions: 7Answers: 0
Hi Allan. I use datatables 1.9.4
In the get.php I use a getFormatter function to calculate the value of a field
Field::inst( 'etl_product_desc' )->getFormatter( function($val, $data, $field) {
..... here I make a select and return the value of 'etl_product_desc' ...
}
Well, I need to calculate inside this function the value of another field that I retrive in this get.php with another "Field::inst"
Is possible ? How can I do ?
Thanks
In the get.php I use a getFormatter function to calculate the value of a field
Field::inst( 'etl_product_desc' )->getFormatter( function($val, $data, $field) {
..... here I make a select and return the value of 'etl_product_desc' ...
}
Well, I need to calculate inside this function the value of another field that I retrive in this get.php with another "Field::inst"
Is possible ? How can I do ?
Thanks
This discussion has been closed.
Replies
Allan
Allan
$editor = Editor::inst( $db, 'vista_etl' )
->fields(
Field::inst( 'id' ),
Field::inst( 'may_id' ),
Field::inst( 'productid' )->set(false),
Field::inst( 'etl_product_desc' )
->getFormatter( function($val, $data, $field) {
global $rdo ;
$psDescripcionDetallada = '' ;
$piProductId = $data['productid'] ;
if (!$piProductId || $piProductId == "") {
//
}
else {
//
$query = "SELECT `a`.*, `b`.`name`, `c`.`headerid`, `c`.`defaultdisplayorder` as `Attributedefaultdisplayorder`, `d`.`name` as `headername`, `e`.`defaultdisplayorder` FROM `productattribute` `a`
WHERE ... ";
//
if (bd_query($query)) {
$psDescripcionDetallada = ' ..... ' ;
$piHeaderId = 0 ;
$i = 0;
while($row = $rdo->fetch_assoc()) {
if ($row['headerid'] != $piHeaderId) {
//
$psDescripcionDetallada = $psDescripcionDetallada . ' ....'
$piHeaderId = $row['headerid'] ;
}
$psDescripcionDetallada = $psDescripcionDetallada . ' ....'
$i++;
} ;
$psDescripcionDetallada = $psDescripcionDetallada . '' . '';
}
else {
};
}; // Del if (!$piProductId || .....
if ($psDescripcionDetallada != "" ) { $data['tiene_desc_etl'] = 'Si' ;} // HERE I CHANGE
return $psDescripcionDetallada ;
})
->set(false),
Field::inst( 'tiene_desc_etl' )->set(false)
)
[/code]
So I understand correctly, is it this part which isn't working as you expected: `$piProductId = $data['productid'] ;` ? I'll try to create an example here that reproduces that error can get back to you.
Allan
I want that if this field 'etl_product_desc' which value I calculate in its getFormatter function (that I show you here) is not empty, then I change the value of 'tiene_desc_etl' with
$data['tiene_desc_etl'] = 'Si' ;
in this line if ($psDescripcionDetallada != "" ) { $data['tiene_desc_etl'] = 'Si' ;} // HERE I CHANGE
I test directly $data['tiene_desc_etl'] = 'Si' without the "if ...." and if doesn´t work too.
Thanks.
The getformatter function works ok (calculate the value for 'etl_product_desc' correctly), but my datatables shows me column 'tiene_desc_etl' with all values to 'No'.