⚠ 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

how do i auto fill my total textbox



chirag262

chirag262
  • profile picture
  • Member

Posted 16 May 2017 - 06:14 AM

Hi,

i am totally new  to use grocerycrud, so i want to know that how do i calculate the salary and autometic display in total textbox,how do i do that.here is my code

 

 

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class ManageAccount extends MY_Controller {
 
public function __construct()
{
parent::__construct();
 
$this->load->database();
$this->load->helper('url');
$this->load->helper('authit');
 
$this->load->library('authit');
$this->load->library('grocery_CRUD');
// $this->load->model('diaryModel');
 
if(!logged_in()) redirect('auth/login');
 
}
 
public function index()
{
if(!logged_in()) redirect('auth/login');
 
$this->showAccount();
}
 
 
public function showAccount()
{
$this->session->selectedMenu = "ManageAccount";
$this->session->selectedSubMenu = "-";
 
try{
$crud = new grocery_CRUD();
 
$crud->set_theme('flexigrid');
$crud->set_table('salary_manage');
$crud->set_subject('એકાઉન્ટ');
$crud->fields('id','pay','gpay','total');
$crud->required_fields('pay','gpay','total');
$crud->columns('pay','gpay','total');
 
 
$crud->callback_field('spcla',array($this,'spcla_callback'));
$crud->callback_before_insert('da',array($this,'totalSalary'));
 
$data['isGrocery'] = '1';
$data['subview'] = $crud->render();
$data['contentHeader'] = "salary manage";
 
$this->load->view('templates/mainLayout',$data);
 
 
}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
 
 
public function totalSalary($value, $row)
{
   return $value.($row->pay + $row->gpay);
}
function spcla_callback($value = '', $primary_key = null)
{
$spcla = '<input type="text"  name="spcla" value="60" disabled=true />';
return $spcla;
}
 
}

 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 16 May 2017 - 12:10 PM

Well my friend u need to hook a javascript to the crud - the same can be achieved by using set_js function. 

With the same - u can add a js file where what u need to do is hook to the on_blur event or on_change event of the field boxes and sum up the same and update the total field.

 

Happy GCing :)