platform icon indicating copy to clipboard operation
platform copied to clipboard

Date Range filter

Open reynoldspaul opened this issue 4 years ago • 7 comments

Is your feature request related to a problem? Please describe. On a screen, I need to filter the data between two dates (for example on an orders report)

Describe the solution you'd like Provide a TD::FILTER_DATE_RANGE

Describe alternatives you've considered Provide a date range filter option in command bar to add date_from and date_to as GET vars in url

reynoldspaul avatar Oct 27 '20 16:10 reynoldspaul

Hey @RaiserWeb. Filters that are specified in the tables actually look like HTTP:

http://example.com/demo?filter[id]=1
$model->where('id', '=', 1)

To resolve this issue:

In fact, we have to make either condition. Or enter a special character for example:

http://example.com/demo?filter[created_at]=2020-10-01~2020-10-27
$model->whereBetween('created_at', ['2020-10-01', '2020-10-27']);

Also, now a separate field is used to set the date range. But we can combine it with DateTime

Would you like to work on it?

tabuna avatar Oct 27 '20 20:10 tabuna

Thanks for the info. For the moment, I've solved by using a custom filter.

namespace App\Orchid\Filters;

use Illuminate\Database\Eloquent\Builder;
use Orchid\Filters\Filter;
use Orchid\Screen\Field;
use Orchid\Screen\Fields\DateRange;

class DateRangeFilter extends Filter
{
    /**
     * @var array
     */
    public $parameters = [
        'filter',
    ];

    /**
     * @return string
     */
    public function name(): string
    {
        return __('Dates');
    }


    /**
     * @return Field[]
     */
    public function display(): array
    {
        return [
            DateRange::make('filter')
                ->title('Date Range')
                ->format('Y-m-d')
                ->value($this->request->input('filter'))
                
        ];
    }

}

// to get dates
$range['start_date'] = $_GET['filter']['start'] ?? date('Y-m-01');
$range['end_date'] = $_GET['filter']['end'] ?? date("Y-m-t", strtotime($range['start_date']));

reynoldspaul avatar Dec 31 '20 10:12 reynoldspaul

@RaiserWeb i dont know if you already did, but can you make a PR with this ? @tabuna this would be very handy

lemyskaman avatar Dec 31 '20 10:12 lemyskaman

I've made a relevant PR: https://github.com/orchidsoftware/platform/pull/1927

lintaba avatar Oct 17 '21 15:10 lintaba

Up for this , seems the PR: #1487 fixes the issue on date range filter.

Using date range filter on table gives incorrect query $query->whereIn instead of $query->whereBetween

yourjhay avatar Jun 23 '22 00:06 yourjhay

image

yourjhay avatar Jun 23 '22 14:06 yourjhay

@yourjhay you must mark your target_date to be casted as a date/datetime to work properly

https://github.com/orchidsoftware/platform/pull/1927/files#diff-ec81588bdcd5635dcb10a3db8d5b33a8e6fb78524a499656b14f2a16f0642b34R243

lintaba avatar Jun 23 '22 15:06 lintaba