livewire-powergrid icon indicating copy to clipboard operation
livewire-powergrid copied to clipboard

Date Picker Filter - Wrong Date ?!

Open pirex360 opened this issue 3 years ago • 6 comments

I have a strange behaviour of filtering dates using flatpickr, (see video). I have records on 12/05/2022... when I choose the exact date on the picker: it returns zero rows.... but if I choose the next day 13/05/2022 all the records of 12/05/2022 are retrieved.

https://user-images.githubusercontent.com/17271768/168447958-377897ee-7809-4571-bb06-3aa0de8c6af9.mp4

So, my flatpickr in the config file is like this :

image

My component , in the addColumn() method image

My component, in the columns() method image

So I think this is something regarding my Carbon transformation.... the data in the database is stored Y-m-d H:I:s, I use the callback to transform to locale date format d/m/Y

pirex360 avatar May 14 '22 21:05 pirex360

This would be the best way:

public function addColumns(): PowerGridEloquent
{
     return PowerGrid::eloquent()
         ->addColumn('data_inicio')
         ->addColumn('data_inicio_formatted', function ($entry) {
               return Carbon::parse($entry->data_inicio)->format('d/m/Y');
         });
}

public function columns(): array
   Column::add()
         ->title('Data Inicio')
         ->field('data_inicio_formatted')
         ->makeInputDatePicker('data_inicio'),

luanfreitasdev avatar May 14 '22 22:05 luanfreitasdev

Don't Work... I have the same behaviour.... The dates of 12/05/2022, only appear when I choose in the date picker 13/05/2022. I wonder if this behaviour is for having the date filter format like 'd/m/Y' but the field rendered is 'd/m/Y H:m:s', using your example... we reference the 'data_inicio' RAW from the database, using default 'Y-m-d H:i:s'

maybe there is a flag for single date selection?

pirex360 avatar May 16 '22 08:05 pirex360

Strange, here the filtering is returning correctly image

luanfreitasdev avatar May 16 '22 19:05 luanfreitasdev

Something wrong with my date... I choose a date between 15 and 16 of May...

inspecting livewire filter date array ... is getting 14 to 15 (midnight) ....

image

pirex360 avatar May 16 '22 20:05 pirex360

Interesting. I'll see if I can find something around here. but feel free to correct and submit a PR!

luanfreitasdev avatar May 16 '22 20:05 luanfreitasdev

I think the same happened here : https://github.com/Power-Components/livewire-powergrid/issues/230

pirex360 avatar May 18 '22 15:05 pirex360

I believe these changes can resolve some of these issues.

https://github.com/Power-Components/livewire-powergrid/pull/778

luanfreitasdev avatar Dec 24 '22 15:12 luanfreitasdev