-1

I have a SAPUI5 SelectDialog control, which contains StandardListItem control inside it to display a list of data, something like this:

enter image description here

I can select each entry one by one.

What I want to achieve, is to provide "SELECT ALL" or "DESELECT ALL" functionality. If I press ctrl+A inside dialog box, it works well & selects all the entries inside the dialog. What I want is to provide a button/checkbox at the top, which user can select to select/deselect all the entries at once. Unlike multicombobox, SelectDialog control does not have inbuilt "Select All" method.

Using tutorial at https://www.w3schools.com/jsref/event_ctrlkey.asp, I tried triggering ctrl+A event using a button, but it seems not working. Any input on this?

Code I tried

<script>event.$(document).ready(function(){
        $("#myButton").click(function () {  
        var triggerEvent = $.Event();
        triggerEvent.buttonevent == 65; //keycode for alphabet A
        triggerEvent.ctrlKey == true;
        $(this).trigger('triggerEvent');
    });
    });</script>



<SelectDialog id="myDialog" growingThreshold="2000" 
        multiSelect="true" noDataText="NoDataFound" liveChange="handleSearchSelectionDialog" items="{model>/data}"
        search="handleSearchSelectionDialog" title="Choose" contentHeight="50%">
        <StandardListItem id="abc" 
            title="SELECT ALL" type="Active"/>
        <StandardListItem id="myId" 
            title="data" type="Active"/>
<button onclick="clicked" id="myButton">SELECT ALL</button>
    </SelectDialog>

Thanks.

Code_Tech
  • 775
  • 13
  • 42
  • why don't you just add a select all option? Much easier to understand than a obtuse keyboard command. You don't need to send a ctrl-a, you just need to select all the drop downs `$(checkbox).prop('checked', true);` etc.. We'd need to see you HTML – Liam Jan 30 '19 at 09:21
  • 1
    @Liam The HTML part is added automatically by the framework _SAPUI5_. Here is a demo: https://ui5.sap.com/#/sample/sap.m.sample.SelectDialog/preview – Boghyon Hoffmann Jan 30 '19 at 11:04
  • See https://github.com/SAP/openui5/issues/2167 for further discussions. – Boghyon Hoffmann Jun 01 '19 at 13:10

1 Answers1

1

I think your solution can be found here: Firing a Keyboard Event in JavaScript

you basically need to trigger two key-events. At first for the ctrl and followed up the 'a'.

var ctrlEvent = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, keyCode : 17, char : 17, shiftKey : true});
var aEvent = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, keyCode : 65, char : 65, shiftKey : true});

document.dispatchEvent(ctrlEvent);
document.dispatchEvent(aEvent);
Peter Hauer
  • 70
  • 1
  • 12