Fullcalendar filtrering events with select

Viewed 1193

I want to filter events by changing a select option, but I'm not sure how. Some help please(I want to clarify that this is the first time I use Json and FullCalendar)

Example:

enter image description here

Controller cCalendar

 public function geteventos(){

    $rut_usu = $this->input->post('rut_usu');
    $r = $this->mCalendar->geteventos($rut_usu);
    echo json_encode($r);



}

Model mCalendar

 public function geteventos($rut_usu){


 $this->db->select('CONCAT(estudiantes.pnombre," ", estudiantes.apellido_pa," ", estudiantes.apellido_ma,", ",motivos_citas.descripcion_mot) As title ,citas.id_ci id, citas.fecha_ini start, citas.fecha_ter end');
 $this->db->from('citas');
 $this->db->join('estudiantes', 'citas.rut_estu = estudiantes.rut_estu');
 $this->db->join('motivos_citas','citas.id_mot = motivos_citas.id_mot');
 $this->db->join('usuarios','citas.rut_usu = usuarios.rut_usu');
 $this->db->where('usuarios.rut_usu',$rut_usu);

 return $this->db->get()->result();


}

Javascript

 $("#rut_usu").change(function(){

  rut_usu = $('#rut_usu').val();

  $.post('<?php echo base_url();?>cCalendar/geteventos',



 $('#calendar').fullCalendar({

  header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay,listMonth'
  },

  defaultDate: new Date(),
  navLinks: true, // can click day/week names to navigate views
  businessHours: true, // display business hours
  editable: true,
  events: $.parseJSON(data) 

    });



  }));
1 Answers

Your controller and modal is not any changes. Only changes in js:

Create new javascript function:

function getEvents(rut_usu)
{ 
    $('#calendar').fullCalendar( 'removeEvents'); 
    $.ajax({
        type:"GET",
        url: "<?=base_url();?>cCalendar/geteventos",
        dataType: 'json',
        data: {rut_usu:rut_usu },
        success: function(data){

            $.each(data, function(index, event){
                $('#calendar').fullCalendar('renderEvent', event);
            });
        }
    });
} 

Call this function into on change dropdown event:

<select id="rut_usu" OnChange="getEvents(this.value);">
-----
</select>

Render Event when change select option.

Related