preSelect based on todays date

preSelect based on todays date

ladokjohanladokjohan Posts: 15Questions: 3Answers: 0

Hello,

I use searchPanes with a custom pane based on these kind of options:

options: [
    {
        label: 'Autumn 2019',
        value: function(rowData, rowIdx) {
            return rowData[3] >= '2019-07-01' && rowData[3] <= '2019-12-31';
        }
    },
    {
        label: 'Spring 2020',
        value: function(rowData, rowIdx) {
            return rowData[3] >= '2020-01-01' && rowData[3] <= '2020-06-30';
        }
    }

etc...

It works fine if I use:

preSelect: ['Spring 2020']

However, I would like to set the preSelect value based on todays date. If todays date is between '2021-07-01' and '2021-12-31' the preselected label will be [Autumn 2021]. Is it possible? If yes, how can I do that?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590
    Answer ✓

    That preSelect in your code is just a string - so you could calculate the season and generate that string in a variable before you initialise DataTables, then pass that string in where your constant currently is. This SO thread has a nice algorithm to work out the season,

    Colin

Sign In or Register to comment.