Not select a row when I edit it

Not select a row when I edit it

jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
edited July 2013 in TableTools
Hi Allan
I want to make a multi-select of rows. But before select a row often I edit the record to review data.
I want that when I press the Edit button, TableTools not select the row, because I only want in this moment review data. Only when I press another element of my row then select the record.
Is possible ? How can I do? What code I must modify ?

I have an inline control button to Edit a record. In Tabletools, I have the parameter "sRowSelect": "multi".
To edit a record :
$('#example').on('click', 'a.editor_edit', function (e) {
editor.edit(..)
}

Can you help me?

Thanks.

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Try this:

    [code]
    $('#example').on('click', 'a.editor_edit', function (e) {
    e.stopPropagation();
    editor.edit( ... );
    } );
    [/code]

    That will stop the click event bubbling through to the row click handler that is placed on the table by TableTools.

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    I try this
    $('#example').on('click', 'a.editor_edit', function (e) {
    e.stopPropagation();
    editor.edit(
    $(this).parents('tr')[0],
    'Record Data',
    { "label": "Update", "fn": function () { editor.submit() } }
    );
    } );

    but the Editor window with the data of my record shows and hides automatically and come back to the menu from I execute my Datatables.
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    That's interesting. That looks like it should work to me. Could you try adding `return false;` to the end of your `on` function?

    Thanks,
    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Hi Allan,

    With this "return false" I get the row shows and wait for updating (not hides automatically and come back to the menu), but the row shows selected in datatables just behind the window editor .
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Right, the row selected in the background and the Editor window showing is what you want is it not?

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    No.
    I want that when I press the Edit button, TableTools not select the row, because I only want in this moment review data. Only when I press another element of my row then select the record.
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    I must confess, I don't understand why that isn't working!

    However, I have a different solution - use the fnPreRowSelect callback of TableTools. THis is called before TableTools selected the row, so you can disallow the selection:

    [code]
    fnPreRowSelect: function ( e, rows ) {
    return e.target.nodeName.toUpperCase() === 'A' ?
    false : true;
    }
    [/code]

    That will detect a click on an `a` tag and disallow the selection.

    Regards,
    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    It doesn´t works because I use a img inside the a tag. I change your code with this :
    fnPreRowSelect: function ( e, rows ) {
    return e.target.nodeName.toUpperCase() === 'IMG' ? false : true;
    }
    and works. Thanks for all Allan. Thanks a lot.
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Hi Allan.I thought it worked, but when i show Mozilla Firebug I get this error :
    "e is undefined" in this line
    ... e.target.nodeName.toUpperCase()

    Why ?
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Oops sorry - I forgot that event.target isn't available in Firefox. Try:

    [code]
    var target = e.target || e.srcElement;
    return target.nodeName.toUpperCase() === 'IMG' ? false : true;
    [/code]

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Hi Allan.
    I try with

    "oTableTools": {
    "fnPreRowSelect": function ( e, rows ) {
    if (!e) {
    e = window.event ;
    }
    var target = e.target || e.srcElement;
    return target.nodeName.toUpperCase() === 'IMG' ? false : true;
    },
    ...}

    and this

    "oTableTools": {
    "fnPreRowSelect": function ( e, rows ) {
    var target = e.target || e.srcElement;
    return target.nodeName.toUpperCase() === 'IMG' ? false : true;
    },
    ...}

    and always firefox debug says to me " e is undefined" in this line "var target = e.target || e.srcElement;"

    Is there something I make wrong? Is PreRowSelect receiving the event ?

    Thanks
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Which version of TableTools are you using? If it isn't the latest - can you try upgrading please?

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    TableTools version 2.1.5
This discussion has been closed.