pheromix
pheromix

Reputation: 19347

How to preselect a range of dates?

The widget is configured to display 2 columns ( months ) :

function initialDateRangePicker(date_logiciel) { // date_logiciel is String representing date in format YYYY-MM-DD
    const picker = new easepick.create({
        element: "#closingDate",
        css: [
            "https://cdn.jsdelivr.net/npm/@easepick/[email protected]/dist/index.css"
        ],
        zIndex: 10,
        lang: "fr-FR",
        format: "DD/MM/YYYY",
        grid: 2,
        calendars: 2,
        plugins: [
            "RangePlugin",
            "KbdPlugin"
        ],
        RangePlugin: {
            delimiter: "  -  ",
        },
        setup(picker) {
            picker.on('select', (e) => {
                let debutObj = e.detail.start , finObj = e.detail.end;
                let debutStr = JSON.stringify(debutObj) , finStr = JSON.stringify(finObj);
                let debuts = debutStr.split("T") , fins = finStr.split("T");
                tableRemiseEnBanqueDatatables.getDatatable().destroy();
                tableRemiseEnBanqueDatatables.init(debuts[0], fins[0], JSON.parse('{ "id_liste": "#listeRemiseEnBanque", "icone": "/img/common/icones/bxs_bank.png", "titre": "Remise en banque" }'));
            });
        }
    });
    return picker;
}

How to make it at document ready to preselect date_logiciel to date_logiciel ?

Upvotes: 0

Views: 73

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196227

Use the startDate and endDate options of the range plugin

...
RangePlugin: {
    delimiter: "  -  ",
    startDate: new Date(date_logiciel),
    endDate: new Date(date_logiciel),
},
...

Upvotes: 1

Related Questions