Show/Hide Details without selecting row

Show/Hide Details without selecting row

ChrisGChrisG Posts: 29Questions: 0Answers: 0
edited August 2013 in TableTools
I have both the Show/Hide details button and the user selectable rows features, and I want to prevent the row from being selected if the user clicks on the show/hide details button only. So basically how do I prevent row selecting if the user clicks on the first column in the table?

I feel like this should be really easy to do but I just don't know how to write it out. I've gotten as far as figuring that I probably need to modify the actual selecting function in TableTools.js

Let me know if I'm way off base.

Replies

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Two options, use TableTools fnPreRowSelect function ( http://datatables.net/extras/tabletools/initialisation#fnPreRowSelect ) to cancel the select when clicked on an img element (assuming you are using an image element), or simply use stopPropagation to cancel the event bubbling up.

    Allan
  • ChrisGChrisG Posts: 29Questions: 0Answers: 0
    What about avoiding a column entirely? Like for example I don't want the row to be selected if the mouse is clicked within the first column or eighth column.

    Since there is space around the Show/Hide image that the user might accidentally click, I want to try to avoid that mistake from happening if possible.

    Thanks for the help!
  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    Currently no - the TableTools click event handler listens on the whole row, so there is no way of specifying which columns (at the moment, I am going to change it in future). I've opened this issue: https://github.com/DataTables/TableTools/issues/30 .

    The other option is to add your own event handler and use the fnSelect API method to select rows using your own logic.

    Allan
  • ChrisGChrisG Posts: 29Questions: 0Answers: 0
    Awesome. I can't wait to see that feature added. It would help me out a lot. I'm a beginner to all of this so I really don't think I'll be able to add my own event handler for selection or anything. I honestly wouldn't know where to start.
  • ChrisGChrisG Posts: 29Questions: 0Answers: 0
    So I'm trying to add my own event handler using fnSelect... but I'm confused as to what the parameters actually do. So far all I've managed to do is alert that nRow[0].id shows the row id that was clicked... But I have no clue as to what oConfig or nButton are actually doing.

    Is there any documentation as to what information these contain? How would I determine what column is being clicked from this information?
  • ChrisGChrisG Posts: 29Questions: 0Answers: 0
    So I solved this with a temporary solution of just modifying the click event in TableTools.js to look at the html info inside a clicked cell and I can then check if the data is null or if the html contains keywords like "details" for the Show/Hide button name... I also have it check if the html contains "href" so that if I have links or thumbnails in a row, the user can click them without actually selecting the row.

    This works great but I'm concerned if I ever need to update my TableTools to a newer version... I commented my code so I can always transfer it over but it would still be good to have a proper fix for this.
This discussion has been closed.