Disable/Enable inline editing via API ?

Disable/Enable inline editing via API ?

JPC!JPC! Posts: 13Questions: 2Answers: 0

I unsuccessfully searched the reference for a method to deactivate or activate inline editing for a table using editor. What I want to do is to set a "readonly" state for a while and to switch the table to writable later.

Thanks for any hint ;-)

Jens

Replies

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Inline editing is triggered by your code calling the inline() method. So the way to disable it is to simply not call that method.

    There are a number of ways of doing that, but the right way will depend upon how you are calling it at the moment. Presumably in an event listener, so you could remove the event listener while in readonly mode, or put a check in the handler to see if you are in readonly mode before calling inline().

    Allan

  • JPC!JPC! Posts: 13Questions: 2Answers: 0

    Hi Allan,

    thanks for your reply ;-)

    At the moment I don't use API explicitly. I call inline functionality by using the following in the table definition to get "Excel like" editing:

        keys: {
            editor: editor,
            className: 'highlight',
        }
    

    This of course is quite static. What I am looking for is to switch on and off inline editing dynamically. Maybe the event listener approach could be interesting for me to check out. Is there any helpful example?

    Jens

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Yep, you can use the KeyTable API for that, keys.enable and keys.disable. In this example, when you click the two buttons above the table, you either enable or disable inline editing.

    Colin

  • JPC!JPC! Posts: 13Questions: 2Answers: 0

    Hi Colin,

    that made the trick ;-)

    I had tried this before, without success. Your example made clear, I had had to check why it didn't work with my code. The reason was my use of a partial view resulting in using the keys.disable() before table initialization. I could resolve that by using the "init.dt" event.

    Now everything is working perfectly, thanks a lot for your and Allan's help. I definitely appreciate receiving your answers within a very short time. Very helpful!

    Jens

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Awesome - great to hear you got it working!

    Allan

Sign In or Register to comment.