Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
388 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...