platform
platform copied to clipboard
Date Range filter
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
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?
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']));
@RaiserWeb i dont know if you already did, but can you make a PR with this ? @tabuna this would be very handy
I've made a relevant PR: https://github.com/orchidsoftware/platform/pull/1927
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 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