简体   繁体   中英

get start day of week and end day fullCalendar

I´m traying to get actual week with fullCalendar plugin in laravel 5.8 . I need get it, to send this date to controller and to do a query with this date.

In my script.js i have a listener click but change my view to week and in this view in title put current week in this format:

8 – 14 mar 2021

i want to get firts day of week and last day of week. Also i´m traying with

var currentDate = calendar
var beginOfWeek = currentDate.startOf('week');
var endOfWeek = currentDate.endOf('week');

but returned me:

currentDate.startOf is not a function

because currentData return empty array... But i´m instaciate my calendar so:

var calendar = new FullCalendar.Calendar(document.getElementById('calendar'), {
    headerToolbar: {
        left: 'prev next today',
        center: 'title',
        right: 'dayGridDay dayGridWeek dayGridMonth listMonth'
    },
    locale: config.lang,
    initialView: 'dayGridMonth',
    displayEventTime: true,
    
    events: dbEvents,

and i have all my events from DB in my calendar... I don´t understand why i can´t use my object to use startOf and endOf .

I don´t know i´m doing well my logic, maybe i should to do this to other form. How can i get current week? and even i want show next or last week that i can get this week ok.

Thanks so much for help, and sorry for my english i hope that you can understand me.

with this function i´m getting my week´s days

/** GET DAYS OF WEEK */
  function getDaysOfWeek(){
    let startDayWeek = calendar.view.activeStart;
    let endDayWeek = calendar.view.activeEnd;

    var firstDay = new Date(startDayWeek);
    var lastDay = new Date(endDayWeek);

    dayStartWeek = firstDay.toISOString().substring(0,10);
    dayEndWeek = lastDay.toISOString().substring(0,10);
  }

I made like this because some end month wasn´t works properly:

function getDaysOfWeek(){
    var calendar = calendarRef.current.getApi();
    let startDayWeek = calendar.view.currentStart;
    let endDayWeek = calendar.view.currentEnd;
    var firstDay = new Date(startDayWeek);
    var lastDay = new Date(endDayWeek);
    firstDay.setDate(firstDay.getDate() + 1);
    lastDay.setDate(lastDay.getDate() - 2);
console.log(firstDay.toISOString().substring(0,10),lastDay.toISOString().substring(0,10));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM