That's gonna take a long time to explain.
Basically AJAX is about fetch data from server and doing some DOM modification.
I'm not sure I can explain it in a post.
This is gonna be a good reference to read http://www.w3schools.com/jquery/jquery_ajax_intro.asp
Basically it is like this:
You have a controller with 2 function. The first function is to show the groceryCRUD, and another function is to show the car which is in the range of date
<?php
class Car_Controller extends CI_Controller{
public function car(){
$this->load->library('groceryCRUD');
$crud = new GroceryCRUD();
// and any other code
$output = $crud->render();
$this->load->view('car_view',$output);
}
public function get_allowed_car_id(){
$this->load->model('car_model');
$start_date = $this->input->post('start_date');
$end_date = $this->input->post('end_date');
$data = $this->car_model->get_car_id_between_date($start_date, $end_date);
echo json_encode($data);
}
}
?>
Suppose you have a form that post start_date and end_date and point to car_controller/get_allowed_car_id
you'll have something like this as output:
[{id:1},{id:3},{id:5}]
Assuming there are car with id 1,3 and 5 available between the date. This kind of format is named JSON (Javascript Object Notation).
Now you want to get such an information everytime your visitor change field-from_date or field-to_date input.
Therefore you'll need a javascript (or easier using JQuery framework) in your car_view.php
<script type="text/javascript">
$(document).ready(function(){
// everytime your input changes, send the ajax request
$('#field-from_date, #field-to_date').change(function(){
// get the value of field-from_date and field-to_date
var from_date = $('#field-from_date').val();
var to_date = $('#field-to_date').val();
// send ajax request, as someone submit something by using post method to your controller
$.ajax({
'url' : 'car_controller/get_allowed_car_id',
'type': 'POST',
'dataType': 'json',
'data': {'from_date':from_date,'to_date':to_date},
'success': function(response){
// okay, here you need to write a script to change the DOM, but for now I'll just show it in javascript console
console.log(response);
}
});
});
});
</script>
Sorry, this might not explain too much :P
You still need to learn AJAX by yourself. But I hope I can give you a "big-picture-idea" about what to do.
Tell me again if you have any problem. Good luck :)
EDIT:
Actually I use such a method in No-CMS module generator. So If you download No-CMS, install it in your computer, and run module generator, you'll find that everytime you change the value of "selection table", the item of the "selection field" will also be affected. But I've mix it up with other function, so it is not so easy to read. In case of you are interested, you can inspect the source code https://github.com/goFrendiAsgard/No-CMS/blob/master/modules/nordrassil/views/data/nds_column.php