cancel
Showing results for 
Search instead for 
Did you mean: 

double click on table row

Former Member

Hello,

some users make a double click on a table row, so the row will be selected on first click and deselected on the second. Is there a way to disable the second click or make a double click work to select a row?

Regards,

Igor

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

I found a solution that worked for me:

in the view:


oTable.attachBrowserEvent("dblclick", oController.onDblClick);

oTable.attachBrowserEvent("click", oController.onClick);

In the controller:


onInit : function() {       

        window.clicks = 0;

        window.selectedIndex = -1;

},

onDblClick : function() {

     oTable = sap.ui.getCore().byId('myTable');

     oTable.setSelectedIndex(window.selectedIndex);

},

   

onClick : function() {

     window.clicks = window.clicks + 1;

       

     if(window.clicks == 1) {

          setTimeout(sap.ui.controller("path.to.controller").clearClicks, 500);

     } else if(window.clicks == 2) {

          oTable = sap.ui.getCore().byId('myTable');

          window.selectedIndex = oTable.getSelectedIndex();

     }

},

clearClicks : function () {

    window.clicks = 0;

    window.selectedIndex = -1;

}

any suggestions?

Regards,

Igor

Former Member
0 Kudos

Hi Igor,

it seems the table component doesn't offer a property to influence this behaviour, so the only way to achieve this is to use a handmade solution as you did.

I've played around a littlebit and came up with a similar solution:


var lastSelIndex = -1;

oTable.attachEvent("rowSelectionChange", function() {

    if (arguments[0].getSource().getSelectedIndex() > -1) {

        lastSelIndex = arguments[0].getSource().getSelectedIndex();

    }

});

oTable.attachBrowserEvent("dblclick", function() {

    if (oTable.isIndexSelected(lastSelIndex)) {

        oTable.removeSelectionInterval(lastSelIndex,lastSelIndex);

    }

    else {

        oTable.addSelectionInterval(lastSelIndex,lastSelIndex);

    }  

    lastSelIndex = -1;

});

One problem with your solution is, it doesn't work when you can select multiple rows.(In your click function you refer to window.selectedIndex = oTable.getSelectedIndex(); which will return the first selected row index, which is wrong when multiple rows are selected...)

Second, the function doesn't behave as expected when the users make some action between the 500ms delay in the setTimeout function.

Hope this is helpful,

greets ben

Former Member
0 Kudos

Hi Ben,

greate work. I've looked for a solution without a timer.

Thank you

Answers (0)