Jump to content


how to add ajax method and calculation

how to add ajax method and ca ajax mysql jquery dependentdown

  • Please log in to reply
7 replies to this topic

#1 Sangat Shah

Sangat Shah

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationAhmedabad

Posted 11 September 2014 - 12:20 PM

this my Controller 
i am fist time use to crocery crud 
 
IDV amount is back and to calculate  formula is =  basic price - (year * deprecation per(%))
and display in idv field textbox 
 
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');
    }
    
    
}

 

Attached Thumbnails

  • untitled.JPG


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 14 September 2014 - 08:38 AM

Well my friend - what i understand loking at this form of yours - u want to generate the vlue of the field mentioned abouve at runtime based on the user selection of values.  If that is so - what you need to do is write an action in controller that accepts a set of values (of definitions) that u wana send across and it returns u the value.

Second thing that you need to do is write a js file which will have a hook to (field - u need to select the field on whose change the value here will get changed) on change event - it calls to a function which makes an ajax call to the above action as described

the value it returns - (on success) - it gets displayed in the text field. - once the js is built - u need to add the same to the crud using set_js functionality.

 

PS -  read the solution 3-4 times if not understood in 1 attempt - the solution provided is a clear need for the outcome expected. Sorry as wouldnt be able to share u coded solution for the same.

 

Happy GCing :)



#3 Sangat Shah

Sangat Shah

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationAhmedabad

Posted 17 September 2014 - 10:45 AM

i can't understand sir 

plz some small example code for me plz help. i am first time use grocery crud



#4 Sangat Shah

Sangat Shah

    Member

  • Members
  • PipPip
  • 16 posts
  • LocationAhmedabad

Posted 19 September 2014 - 07:55 AM

Well my friend - what i understand loking at this form of yours - u want to generate the vlue of the field mentioned abouve at runtime based on the user selection of values.  If that is so - what you need to do is write an action in controller that accepts a set of values (of definitions) that u wana send across and it returns u the value.

Second thing that you need to do is write a js file which will have a hook to (field - u need to select the field on whose change the value here will get changed) on change event - it calls to a function which makes an ajax call to the above action as described

the value it returns - (on success) - it gets displayed in the text field. - once the js is built - u need to add the same to the crud using set_js functionality.

 

PS -  read the solution 3-4 times if not understood in 1 attempt - the solution provided is a clear need for the outcome expected. Sorry as wouldnt be able to share u coded solution for the same.

 

Happy GCing :)

thanx Amit 

yes i can do it successfully  



#5 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 19 September 2014 - 10:41 AM

Well done... Happy to help you out :)

Happy GCing :)



#6 armlis

armlis

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 07 July 2015 - 04:59 PM

thanx Amit 

yes i can do it successfully  

Great !!!

 

Coul'd you explain or better :  post/show your final code. I need exatly the same fonctionnality.

 

I understand well your first post with your code, it looks like coul'd help my need.

 

I see (I read a lot of time Amit solution) what to do, but it's a bit short for me, newbee with codeIgniter and GroceryCrud :)

 

Thanks a lot

Lionel



#7 HACK

HACK

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 16 January 2017 - 10:27 AM

nice to meet you all, im new using grocerycrud

 

i have a problem with same case ... 

 

i was create simple JS file then set_js to template add.php ....... it's showing alert if i just put alert('') in my_js.js 

 

then  i change to

$(".sewa_dp").change(function(){	
	alert('');
})

my view using  callback_field to create ID 

$crud->callback_field('sewa_dp', function () {
  return 'Rp. <input type="text" maxlength="20" value="0" name="sewa_dp" id="sewa_dp"> ';
});

when i change value sewa_dp .. its dont show alert for that ... anyone can help me ???  



#8 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 18 January 2017 - 02:00 AM

Hi HACK,

 

What you are trying to do is .. make a call on change .. of a class ..

Your code ...... $(".sewa_dp").change(function(){ ....

There.. i may be able to work successfully with the pre-generated code. You have hooked the js call on the class sewa_dp

then when u doing a callback - you overriding the output generated earlier by the GC library and getting your own code.. if u see in there.. there is noclass sewa_dp available

This is the reason - you are not getting an alert ...







Also tagged with one or more of these keywords: how to add ajax method and ca, ajax, mysql, jquery, dependentdown

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users