I apologize if the answer is already here but I am having trouble finding it. I have two n_n tables that I need to combine their values. For simplicity this is what I'm after:
My tables:
PRODUCT
----------------
ID | product_id
NAME |product_name
COLOR
-------------------------
PID | color_id
ID | product_id
COLOR | color_name
SIZE
-------------------------
PID | size_id
ID | product_id
SIZE | size_name
The end result needs to be:
PRODUCTS DISPLAYED
-------------------------
ID | product_id
NAME | product_name
OPTIONS | color_name size_name, color_name size_name, color_name size_name
If I set the columns to show all the columns I can use callback to merge the COLOR and SIZE columns as one:
$crud->columns('ID','NAME','COLOR','SIZE');
$crud->callback_column('COLOR',array($this,'_merge_string'));
[some $crud->display_as magic]
public function _merge_string($value, $row){
$value = $value.",".$row->SIZE;
return $value;
}
But the resulting table is rendered as:
PRODUCTS DISPLAYED-------------------------
ID | product_id
NAME | product_name
OPTIONS | color_name size_name, color_name size_name, color_name size_name
SIZE | size_name, size_name, size_name
If I unset the SIZE that I no longer need, the SIZE column is removed from the rendered table but the value is no longer available for the callback.
$crud->columns('ID','NAME','COLOR','SIZE');
$crud->callback_column('COLOR',array($this,'_merge_string'));
[some $crud->display_as magic]
public function _merge_string($value, $row){
$value = $value.",".$row->SIZE;
return $value;
}
$crud->unset_columns('SIZE');
PRODUCTS DISPLAYED
-------------------------
ID | product_id
NAME | product_name
OPTIONS | color_name, color_name, color_name
Is there a way to hide the SIZE column from the final output without losing access to its values for the callback to merge it with COLOR?
Thanks!