PreCreate event on dblclic... no row selected

PreCreate event on dblclic... no row selected

LapointeLapointe Posts: 430Questions: 81Answers: 4

Hello all
I try to get the value of a field in the row I dblclic on (single select).. Dblclick set selected deselected selected....

.on( 'preOpen', function ( e, mode, action ) {
    var selected = table.rows( { selected: true } );
        if ( selected.any() ) {   // sometime return none, sometime correct value depending of dblclick speed

Is there a way from the event to get data of row firing event ? I Use

e.currentTarget.s.editData["FieldName"][e.currentTarget.s.modifier.id]

but not sure it is the good way to....

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin

    If this is inside preOpen then use modifier() to get information about how the edit action was triggered (i.e. the cell, or row index).

    That said, if you want to use a double click event, then you might be better changing this line to match that.

    Allan

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    hi @allan
    I think the link you give me is a single click. Am I wrong ?
    I use single click to select row and double click to open row in edit mode.

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    In fact I catch event in preopen because I set .on (dblclick to open editor in edit mode and want to cancel open for some record regarding value of some field in it

  • allanallan Posts: 61,627Questions: 1Answers: 10,090 Site admin
    Answer ✓

    You are not wrong. As I indicated, you'd need to change that to be a double click event listener if you want to select rows on double click.

    Note that you shouldn't use both click and dblclick on the same elements in the browser since it is impossible to determine if the second click is due to a real second click, or the activation of dblclick. As PPK says:

    The dblclick event is rarely used. Even when you use it, you should be sure never to register both an onclick and an ondblclick event handler on the same HTML element. Finding out what the user has actually done is nearly impossible if you register both.

    Allan

  • LapointeLapointe Posts: 430Questions: 81Answers: 4

    hi @allan
    I do not set something on single click, but single select a row where the click on by default... and single select buttons react at first click of dblckick... It's ok for me because I do not catch this event (single...).
    So I do not want to change the select method of something using single click...

    Dblclick (for me) launch edit window (single row of course) and user do not need to click on edit button (not displayed in fact). Otherpoint is dblclick can never select more than 1 row each time.

    the methos I use

    e.currentTarget.s.editData["FieldName"][e.currentTarget.s.modifier.id]
    

    do the job but I'm afraid (not sure) a major update can change fct of this point...

    Thanks

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited August 2020

    FWIW, the ppk referenced in https://datatables.net/forums/discussion/comment/161983/#Comment_161983 is now at https://www.quirksmode.org/js/events_mouse.html

    @lapointe, I found this post because I want to do exactly what you are doing, i.e., to select the row on click, and edit the row on double click. Do you mind posting your double click event handler (and possibly other relevant handlers) so I can review to see if it meets my needs?

    My needs may be simpler than yours as I don't have the complication of needing the cancel the open for some data in the form.

    I don't want to patch the select extension as I may take updates in the future and wouldn't want to have to remember to keep making the patch, so I hope you didn't end up doing that.

  • LapointeLapointe Posts: 430Questions: 81Answers: 4
            $('#dataTbl').on( 'dblclick','tbody tr', function (e) {
                editor
                    .title('Some title (Edit mode)')
                    .edit( this )
                    .buttons ([
                        {text: 'Save', action: function () {this.submit();}},
                        {text: 'Cancel', action: function () {this.close();}}
                    ])
                    ;
                }
             )
    

    Hope this will help

This discussion has been closed.