如何在杂货店中添加ajax方法进行计算

时间:2014-09-12 05:42:04

标签: jquery ajax codeigniter-2 grocery-crud

这是我第一次使用杂货店。

我想从电机的Cubic Capacity计算电机的IDV,以及它是当年制造年份的基本价格。

计算IDV =基本价格的公式 - (年*(DEP.PERCENTAGE))

这是我的控制器

class TwoWheelerPramiumCalc extends CI_Controller
{
    function __construct() {
    parent::__construct();
    $this->load->database();
    $this->load->helper('url');
    $this->load->library('grocery_CRUD');

}

public function index()
{
   $crud = new grocery_CRUD();
   $crud->set_table('two_wheeler_pramium_calc');
   $crud->set_subject('Two Wheeler Pramium Calc.');
   $crud->display_as('non_life_insurer_id','Insurer  Name');
   $crud->set_relation('non_life_insurer_id', 'non_life_insurer', 'insurer_name');

   $crud->display_as('two_wheeler_make_id','Two Wheeler Make');
   $crud->set_relation('two_wheeler_make_id', 'two_wheeler_make', 'two_wheeler_make');

   $crud->display_as('two_wheeler_model_id','Two Wheeler Model');
   $crud->set_relation('two_wheeler_model_id', 'two_wheeler_model', 'two_wheeler_model');


   $crud->display_as('two_wheeler_variant_id','Two Wheeler Variant');
   $crud->set_relation('two_wheeler_variant_id', 'two_wheeler_variant', 'two_wheeler_variant');

   $crud->display_as('cubic_capacity','cubic_capacity');
   $crud->set_relation('cubic_capacity', 'two_wheeler_variant', 'cubic_capacity');

   $crud->display_as('year','year');
   $crud->set_relation('year', 'two_wheeler_price', 'year');






$this->load->library('gc_dependent_select');
// settings

$fields = array(

    // first field:
    'two_wheeler_variant_id' => array( // first dropdown name
    'table_name' => 'two_wheeler_variant', // table of country
    'title' => 'two_wheeler_variant', // country title
    'relate' => null // the first dropdown hasn't a relation
    ),
    // second field
    'cubic_capacity' => array( // second dropdown name
    'table_name' => 'two_wheeler_variant', // table of state
    'title' => 'cubic_capacity', // state title
    'id_field' => 'two_wheeler_variant_id', // table of state: primary key
    'relate' => 'two_wheeler_variant_id', // table of state:
    'data-placeholder' => 'select state' //dropdown's data-placeholder:

    ),

    // second field
    'year' => array( // second dropdown name
    'table_name' => 'two_wheeler_price', // table of state
    'title' => 'year', // state title
    'id_field' => 'two_wheeler_variant_id', // table of state: primary key
    'relate' => 'two_wheeler_variant_id', // table of state:
    'data-placeholder' => 'select year' //dropdown's data-placeholder:

    ),



);

$config = array(
'main_table' => 'two_wheeler_pramium_calc',
'main_table_primary' => 'two_wheeler_pramium_id',

"url" => base_url() .'index.php/'. __CLASS__ . '/' . __FUNCTION__ . '/' ,
'ajax_loader' => base_url() . 'ajax-loader.gif' // path to ajax-loader image. It's an optional parameter

 );
$categories = new gc_dependent_select($crud, $fields, $config);

// first method:
//$output = $categories->render();

// the second method:
$js = $categories->get_js();





$output = $crud->render();
$output->output.= $js ;
$this->_example_output($output);
   //$output = $crud->render();
   //$this->_example_output($output); 
}
function _example_output($output = null)
{
    $data['title']='Branch';
    $this->load->view('template/header.php',$data);  
    $this->load->view('menu/menu.php');  
    $this->load->view('OutputList.php',$output); 
    $this->load->view('template/footer.php');
}

}

0 个答案:

没有答案