KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How do I change the label in the "custom range" date range selector? I couldn't find that information in the documentation. #3472

Open Pablo Tavares opened this topic on 5 days ago - 1 comments

Pablo Tavares commented 5 days ago

<?php

namespace App\Dashboard\Contrato;

use \koolreport\dashboard\inputs\DateRangePicker;

class PeriodoRanger extends DateRangePicker
{
    protected function onCreated()
    {
        $this->defaultValue($this::thisMonth());
    }

    protected function onInit()
    {
        // $this->format("MMM Do, YYYY")
        // ->value(["2020-01-01 00:00:00","2020-03-01 00:00:00"])
        // ->language("en")
        // ->minDate("2020-01-01 00:00:00")
        // ->maxDate("2020-04-01 00:00:00")
        // ->icon("fa fa-calendar-alt")
        // ->caret("fa fa-caret-down")

        $this->ranges([
            "Hoje" => DateRangePicker::today(),
            "Ontem" => DateRangePicker::yesterday(),
            "Últimos 7 dias" => DateRangePicker::last7days(),
            "Últimos 30 dias" => DateRangePicker::last30days(),
            "Este mês" => DateRangePicker::thisMonth(),
            "Último Mês" => DateRangePicker::lastMonth(),
            "Este Ano" => $this->thisYear(),
            "Ano Anterior" => $this->lastYear(),
            "Dois Anos Atrás" => $this->lastTwoYears(),
        ]);
    }

    protected function actionChange($request, $response)
    {
        //On client change, update        
        $this->sibling("ValorCompradoContratos")->update();
        $this->sibling("VolumeCompradoContratos")->update();
        $this->sibling("StatusContratosPie")->update();
        $this->sibling("ProdutosMaisCompradosContrato")->update();
    }

    static function thisYear()
    {
        $start = new \DateTime('first day of January this year');
        $end   = new \DateTime('today');

        return array($start->format('Y-m-d 00:00:00'), $end->format('Y-m-d 23:59:59'));
    }    

    static function lastYear()
    {
        $start = new \DateTime('first day of January last year');
        $end = new \DateTime('last day of December last year');
        // $start->sub(new \DateInterval('P30D'));
        return array($start->format('Y-m-d 00:00:00'), $end->format('Y-m-d 23:59:59'));
    }

    static function lastTwoYears()
    {
        $start = new \DateTime('first day of January this year');
        $start->sub(new \DateInterval('P2Y'));
        $end = new \DateTime('last day of December this year');
        $end->sub(new \DateInterval('P2Y'));
        return array($start->format('Y-m-d 00:00:00'), $end->format('Y-m-d 23:59:59'));
    }

}
Sebastian Morales commented 4 days ago

Pls try this:

    protected function onInit()
    {
        ...
        $this->language([
            "customRangeLabel" => "My Custom Range Text"
        ]);
    } 

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
bug
help needed

Inputs