Fullcalendar - Can we add custom data to our event Json Data?

前端 未结 5 1130
逝去的感伤
逝去的感伤 2021-01-11 19:55

I want to send a type in my Event Json Response.

Here is my code:

$(\'#calendar\').fullCalendar({

eventSources: [ 

{\"id\":\"46_l\",\"title\":\"Cus         


        
相关标签:
5条回答
  • 2021-01-11 20:34

    In version 4 custom data is in extendedProps.

    In short e.event.extendedProps

    0 讨论(0)
  • 2021-01-11 20:35

    Try It with events: instead of eventSources:

    $('#calendar').fullCalendar({
    
     events: [ 
    
    {"id":"46_l","title":"CustomEvent-Chargement","start":"2013-12-02","end":"2013-12-03","className":"customEventsClass","type":1},
    {"id":"46_d","title":"Custom Event-Livraison","start":"2013-12-11","end":"2013-12-12","className":"customEventsClass","type":2}
    
    ]
    
    });
    
    0 讨论(0)
  • 2021-01-11 20:51

    In the new version you should do this:

    eventRender: function (info) {
        info.el.firstChild.innerHTML = info.event.extendedProps.type + " " + info.event.extendedProps.customEventsClass;
    }
    
    0 讨论(0)
  • 2021-01-11 21:00

    You can also pass url endpoint to events as long as the url returns json response

                cId.fullCalendar({
                 header: {
                    right: '',
                    center: 'prev, title, next',
                    left: ''
                 },
    
                theme: true, //Do not remove this as it ruin the design
                selectable: true,
                selectHelper: true,
                editable: true,
                 //it will load data from this url
                events: "{{ url('api/events') }}",
    //               events: getData(),
    
                //Add Events
            });
    

    and in your controller or function

      $events = $request->user()->events()->select('title','color','date')->get();
    
       //        dd($even,$events)
              $eventsResponse = [];
     //        created_at->format('Y-m-d')
              foreach ($events as $event)
              {
               $eventsResponse[] = [
                'title'=>$event->title,
                'color'=>$event->color,
                'start'=> Carbon::parse($event->date)->toDateTimeString(),
               ];
            }
    
           return $eventsResponse;
    
    0 讨论(0)
  • 2021-01-11 21:01

    As per the documentation:

    Non-standard Fields

    In addition to the fields above, you may also include your own non-standard fields in each Event Object. FullCalendar will not modify or delete these fields. For example, developers often include a description field for use in callbacks such as eventRender.

    Example:

    $('#calendar').fullCalendar({
        events: [
            {
                title: 'My Event',
                start: '2010-01-01',
                type: 1 // Custom field
            }
        ],
        eventRender: function(event, element) {
            console.log(event.type); // Writes "1"
        }
    });
    
    0 讨论(0)
提交回复
热议问题