What selector gets cell that was clicked on?

What selector gets cell that was clicked on?

Karl53Karl53 Posts: 72Questions: 29Answers: 0
edited May 2015 in Editor

Editor v1.4. Inline editing.

In the preOpen event, what jQuery selector should I use to return the cell the user clicked on? And then, how do I check if it has 'my-class' assigned to it? (The class name I'm after is the name assigned in the tables columns property className.)

I use this in the open event and it works just fine (because I guess the editor is created) but it is not working in preOpen

    cell = $('div.DTE').parent();
    cell.hasClass('my-class');

Thank you.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Use the modifier() method to get the "modifier" that was used to trigger the editing - e.g. the cell in this case.

    Allan

  • Karl53Karl53 Posts: 72Questions: 29Answers: 0
    edited May 2015

    Thanks Allan.

    I'm having a problem getting what I need. In Editor's preOpen event handler, editor.modifier() seems to be returning the index of the row being edited. If that's the case, how does that help me know what cell is about to be edited (or even what column the cell is in)?

    This is what I need to be able to do. My interface is very rule based.

    If a the value in cell in column 2 in the row (inline() editing) is equal to say '2', I want to prevent the editor from opening in say the cell in the same row in column 6. I have to be able to prevent the Editor open (thus want to return false in preOpen) whether the user has navigated to the cell using the keyboard, by clicking on it with a mouse or even if they touched it.

    My columns are in a static order, so knowing either the column number or the className of the column the editor is about to act upon would work for me.

    Is editor.modifier() in the preOpen event really the solution for this?

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Can you show me the code you are using please? I had assumed that you are using an event handler to trigger inline editing on a cell, but that won't be the case if you are getting a row index from modifier().

    Allan

  • Karl53Karl53 Posts: 72Questions: 29Answers: 0

    Actually, your reply gave me another idea, but here's the code:

            $('#TVM').on('click', 'tbody td:not(:first-child)', function (e) {
                editor.inline(this);
            });
    
            editor
                .on('preOpen', function (e) {
                    var m = editor.modifier();
                })
    

    var m is an integer.

    Since I'm trapping the keydown.editor event following your tab navigation example, and the click event is being fired there, I can block the editor from opening in above code. I don't have to block in preOpen. But still, I would be interested in knowing if you expect m to be an integer or not.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    That sounds like a bug to me - it should be the cell node. Let me look into it (travelling at the moment) and confirm if it is fixed in 1.5 (it should be - I've completely rewritten that part).

    Allan

  • Karl53Karl53 Posts: 72Questions: 29Answers: 0

    Hi Allan - did you have a chance to look at this? That is, are you able yet to confirm if this is a DataTable bug?

    Thanks,
    Karl

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Sorry, yes, I forgot to reply. This is a bug and it is fixed in 1.5, which is as yet unreleased (it will be later this month :-) ). Using modifier() after calling inline() passing a cell will cause modifier() to return a cell.

    Allan

  • Karl53Karl53 Posts: 72Questions: 29Answers: 0

    Thanks for the update.

This discussion has been closed.