⚠ 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

Setting display_as to a datatable field



navajo

navajo
  • profile picture
  • Member

Posted 26 June 2019 - 10:27 AM

Is there any way of using the display_as function to dynamically display the contents of data table field in the same table.

 

On add or edit a record, the user will fill in a varchar (30) name. I wanted to take this information as the field name in the read pane.

        
            $crud->display_as('ncr_supporting01',$row-->supp01_desc);

            $crud->field_type('supp01_desc','hidden');

 

 

Any suggestions?


navajo

navajo
  • profile picture
  • Member

Posted 28 June 2019 - 13:44 PM

Ok I figured it out. For anyone interested..

 

elseif ($state == 'read')
        {
            $crud->set_primary_key('idnumber','members');
            $crud->set_relation('ncr_due_by','members','{lastname} {firstname}');
            
            $fields = $this->_get_fields($state_info->primary_key);
            If ($fields->supp01_desc =='')
            {
            }
            else
            {
                $crud->display_as('ncr_supporting01',$fields->supp01_desc);
            }

 

 

Then the function:

 

 protected function _get_fields($ncr_no)
    {
        $select = "SELECT * FROM ncrs WHERE ncr_code=$ncr_no";
        $query = $this->db->query($select);
        if ($query->num_rows() == 1) {
            return $query->row();
        } else {
            return null;
        }
    }