regexp time >= 21:00

regexp time >= 21:00

rf1234rf1234 Posts: 3,006Questions: 87Answers: 421
edited February 2023 in DataTables

I have this button:

{   text: lang === "de" ? "Nur Zeit ab 21:45" : "Only Time from 21:45",
    action: function ( e, dt, node, config ) {
        dt.columns("#lateWorkers").search( '^.+$', true, false ).draw();
    }
},

The regexp written by Kevin @kthorngren searches for "not empty" but I would like to replace it by ">= 21:45" for example (time will be a parameter with time running from 00:00 to 23:59).

I am not smart enough to make that regexp. Could anyone help, please?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961
    Answer ✓

    I think you will need to create a range search plugin like this example. I don't know of a way to use regular expressions for time ranges.

    Kevin

  • rf1234rf1234 Posts: 3,006Questions: 87Answers: 421

    Ok, no regex then :smile:

    This is my solution:

    ....
    $.fn.dataTable.ext.search.push(function (settings, data, dataIndex, row, counter) {
        //when is "2022-07-08 10:12:36". We use "10:12" as time.
        var time = row.login_logout_log.when.slice(-8).substr(0,5);
        if ( time >= $('#loginLogoutLogStartTime').val() ) {
            return true;
        }
        return false;
    });
    
Sign In or Register to comment.