⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

column field cumulation computed from another column



bvarlb
  • profile picture
  • Member

Posted 19 April 2013 - 14:07 PM

Hi all,

 

I have a column 'kilometers' in a flexigrid, the value is computed in a callback_column function

I want to display another column beside that is 'total_kilometers' for the cumulation

How can I do that in another callback_column function ?

 

Thanks in advance


davidoster
  • profile picture
  • Member

Posted 21 April 2013 - 00:14 AM

1. use the columns function to add a new column (total_kilometers).

2. use the callback_column to change the value of the column (total_kilometers) by using the $row->kilometers


heruprambadi
  • profile picture
  • Member

Posted 21 April 2013 - 15:39 PM

read the last post. that is exactly what you want /topic/1585-how-to-plus-database-column-in-gc/


bvarlb
  • profile picture
  • Member

Posted 21 April 2013 - 19:54 PM

Hi all,

 

thank you for your help, but let me give more details about my needs :

I don't want to get the total kilometers (between A and D in the example below).

I want to sum kilometers with kilometers of previous line to display for example :

From   To     Kms      total kms

A         B      12         12

B         C      5           17

C         D      8           25

In the controller, I use already a callback_column to get kms because I use a complex query to get it from another joined tables.

 

I think I could use a specific view in which a variable total_kms should be computed in php code in the view. What do you think of that idea because I don't see how to compute total_kms in another callback_column ?

 

Thanks in advance for your help


bvarlb
  • profile picture
  • Member

Posted 24 April 2013 - 07:16 AM

Hi all,

 

Just to say I've found a workaround solution. I use the callback_column :

$crud->callback_column('cumul_kms', array($this, '_cumul_kms_callback'));        

 

  function _cumul_kms_callback($value, $row)
  {
    // cumul kms des étapes de ce parcours <= n° ordre
    $tot_kms = $this->Circuits_model->kms_cumul($row->id_circuit_parcours, $row->id_order);
    return ($tot_kms);
  }

 

in the model Circuits_model :

  function kms_cumul($id_circuit_parcours, $id_order)
  {
    $sql="select sum(nb_kms) as total_kms
          from parcours, distances
          where id_dist_parcours = id_dist
          and id_order <= $id_order
          and id_circuit_parcours = $id_circuit_parcours";
    $query = $this->db->query($sql);
    $row = $query->row();
    $total_kms = $row->total_kms;
    return $total_kms;
  }
Thanks for your help