DataTables buttons on wheel click

DataTables buttons on wheel click

pmatveevpmatveev Posts: 7Questions: 3Answers: 0

Hi,

I am using DataTables button as a link to another page, code is shown below. However I cannot find a way to handle wheel click on the button in order to open the same link in new tab because href is set to '#'. It seems like the action is never executed on a wheel click, so e.preventDefault() won't help...

Is there a way to support wheel click?

action : function(e, dt, node, config) {
                var processedLink = link;
                ref.forEach(function(currentValue, index, array) {
                    processedLink = processedLink.replace("{" + index + "}", dataTablesSelected(dt, currentValue, button.attr("extend")));
                });
                
                window.location = processedLink;
            }

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin
    Answer ✓

    Interesting. Buttons simply uses:

    .on( 'click.dtb', function (e) {
    

    It looks like click isn't actually activated from the mouse wheel. You'd need to listen for mousedown on the button (button().node()) and then use the mouse button in the event passed into the handler.

    Allan

  • pmatveevpmatveev Posts: 7Questions: 3Answers: 0

    Hi Allan,

    Thanks - this helped. Was tricky though as long as I did not find any place to pass the url...

  • arunjaykrishnanarunjaykrishnan Posts: 18Questions: 3Answers: 0

    Hi Allan,

    We were facing the same issue when using datetime and date types. We need to click out twice for the button to trigger the action. We hade fixed this by adding the following code to our js class as per your suggestion above and it worked. Thanks!!
    dt.buttons(0)nodes().on( 'mousedown.dtb', function (e) {
    if ( ! _dt.buttons([ 0]).nodes().hasClass( "disabled" ) ) {
    _dt.buttons([ 0]).trigger();
    }
    } );
    If possible, can you please add this change to the datatables.buttons.js itself.

    Thanks,
    Arun

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    Hi Arun,

    Could you give me a link to an example showing the issue please? I'm not quite clear how this relates to the mouse scroll wheel button issue in the original question here.

    Thanks,
    Allan

  • arunjaykrishnanarunjaykrishnan Posts: 18Questions: 3Answers: 0

    Hi Allan,

    I understand that without showing the link you will not be able to get the issue and I am unable to share the link as this is an internal application that has copyrighted code. Sorry about that, but I will try to provide as much information as possible for your analysis.
    1. Version used: Datatables - 1.10.16, Editor - 1.7.3, Buttons - 1.5.2
    2. Type of Editing - Inline, buttons defined along with datatable configuration e.g. "buttons" : [ {....}]
    4. Issue - When I type in a date for a field of type date click outside and click on save button. nothing happens. When I added console.log in the function .on( 'click.dtb', function (e) {... it was not logged. If I click outside the datatable a second time and then click save, the log shows up in console as well as the action is triggered.
    5. Resolution: If I added trigger action on 'mousedown.dtb'. This issue is resolved.

    Can you please try with a date field and see whether this issue happens for you?
    Please let me know if you need further information to replicate this.

    Thanks for looking into this.

    Regards,
    Arun

  • arunjaykrishnanarunjaykrishnan Posts: 18Questions: 3Answers: 0

    This issue of click not working where as mouse up and mouse down works is happening only with Internet Explorer and works fine with Firefox. The version we are using is IE11.

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    Can you show me your Javascript initialisation for Editor / DataTables please?

    Allan

This discussion has been closed.