Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refreshEvents not working #61

Closed
alucard29 opened this issue Dec 1, 2022 · 4 comments
Closed

refreshEvents not working #61

alucard29 opened this issue Dec 1, 2022 · 4 comments

Comments

@alucard29
Copy link

Hi,
I'm using the last version. The $this->refreshEvents(); method doesn't do anything. as example :

    public function editEvent(array $data): void
    {
       $this->event->start_date = $data['start'];
       $this->event->end_date = $data['end'];
       $this->event->requested_resources = $data['extendedProps']['requested_resources'];
       $participants = Human::whereIn('name',$data['extendedProps']['participants'])->get();
       $this->event->participants()->syncWithoutDetaching($participants);
       $this->event->save();
       $this->refreshEvents();
    }

after the function, the page isn't refreshed.
thx

@torriv83
Copy link

I had the same problem.

How to fix:

  1. In getViewData() function, return an empty array:
public function getViewData(): array
{
    return [];
}
  1. Put your query in your fetchEvents() function

@darkavatar23
Copy link

darkavatar23 commented Jan 11, 2023

Same problem, different situation , when $this->event->update the refresh works, instead $this->event->delete make refresh not working anymore

public function editEvent(array $data): void {
		if($data['active']){
			$this->event->update($data);
		}else{
			$this->event->delete();
		}	
		$this->refreshEvents();
}

@LiberatoDaniel
Copy link

I removed the fetchEvents method and put my query in just getViewData() and that way it gets all the events updated in the database according to the query.

my code looked like this.


namespace App\Filament\Widgets;

use App\Filament\Pages\Roteiro;
use Illuminate\Support\Facades\Session;
use Saade\FilamentFullCalendar\Widgets\FullCalendarWidget;

class RoteiroCalendarWidget extends FullCalendarWidget
{
protected $listeners = [
'refreshEventsCalendar' => 'refreshEventsCalendar',
];

/**
 * Return events that should be rendered statically on calendar.
 */
public function getViewData(): array
{
    $filterSession = Session::get('dataRefreshEventsCalendar');

    $dados = [];
    \App\Models\Roteiro\Roteiro::query()
                               ->with( [ 'user' , 'estabelecimento' ] )
                               ->when( !empty($filterSession['user_id']) , function( $query ) use ( $filterSession ) {
                                   $query->whereIn( 'user_id' , $filterSession['user_id'] );
                               } )
                               ->when( !empty($filterSession['estabelecimento_id']) , function( $query ) use ( $filterSession ) {
                                   $query->whereIn( 'estabelecimento_id' , $filterSession['estabelecimento_id'] );
                               } )
                               ->get()
                               ->map( function( $roteiro ) use ( &$dados ) {
                                   $dados[] = [
                                       'id'    => $roteiro->id ,
                                       'title' => $roteiro->user->name . ' - ' . $roteiro->estabelecimento->nome ,
                                       'start' => $roteiro->data_roteiro ,
                                   ];
                               } );

    return $dados;
}

// REMOVED METHOD fetchEvents
// /**
// * FullCalendar will call this function whenever it needs new event data.
// * This is triggered when the user clicks prev/next or switches views on the calendar.
// */
// public function fetchEvents(array $fetchInfo): array
// {
// return [];
// }

public function refreshEventsCalendar($data)
{
    Session::put('dataRefreshEventsCalendar', $data);
    $this->refreshEvents();
}

}

@mohan-nishit
Copy link

I had the same problem.

How to fix:

  1. In getViewData() function, return an empty array:
public function getViewData(): array
{
    return [];
}
  1. Put your query in your fetchEvents() function

I can confirm this works perfectly. If you have existing logic in getViewData(), return a blank array instead and move the logic to fetchEvents() function.

@saade saade closed this as completed May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants