Get all Keys from Key Event even if DataTables already uses them interally

Get all Keys from Key Event even if DataTables already uses them interally

tobias.pitzertobias.pitzer Posts: 2Questions: 1Answers: 0

Link to test case: http://live.datatables.net/gumizoco/3/edit?js,console,output
Debugger code (debug.datatables.net): https://debug.datatables.net/ayoxub
Error messages shown: None
Description of problem:
The key Event is working fine for every key exept for those keys who are already used by DataTables. For Example: Escape, Arrow Up, Arrow Down, Home, End, ...

This is because KeyTable only emits an event if the switch case doesn't match:

// Line 861
case 27: // esc
        if ( this.c.blurable && enable === true ) {
                this._blur();
        }
        break;
        
// Line922
default:
        // Everything else - pass through only when fully enabled
        if ( enable === true ) {
                this._emitEvent( 'key', [ dt, e.keyCode, this.s.lastFocus.cell, e ] );
        }
        break;

What i want to do is (as you can see in my Example Code). I want to use the Escape Key not just to blur but to refocus on the search Input.

Is there any way i can do this?
Could you maybe emit the key Event even if something else is happening?

Thanks.
Best Regards.

Tobi

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590
    edited September 2021

    Yep, that's the way it's been designed to behave, and people are using it in that way so it's not something we could change. The library is open-source, so you could modify it to behave in the way you need,

    Colin

  • tobias.pitzertobias.pitzer Posts: 2Questions: 1Answers: 0

    Yeah sure, i could do this.

    However my thought was, that you can for example enable this with a special parameter? This way everyone using it would be fine an those you need the events could get them as well.

    Something like "forwardKeyEvent".

    Since i only need two key events i will just make my own version of keytables and add the

    this._emitEvent( 'key', [ dt, e.keyCode, this.s.lastFocus.cell, e ] );
    

    at the places i want it to.
    The only "annoying" part of this, is that you can't use npm.

    Thanks for your help.

    Tobi

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Hi Tobi,

    Such a change would still cause backward incompatibility issues. Possibly a new key-handled event might be more suited?

    Allan

Sign In or Register to comment.