cancel
Showing results for 
Search instead for 
Did you mean: 

Using Hotkeys Api and use switch method to switch between the Shortcuts in SAPUI5.

mahmood_hammood
Participant
0 Kudos
157

Hello everyone,

I try to use Hotkey Api file as in this blog Hotkey Api and have some questions. First Api file called Hotkey.js. How can I call the hotkeys which are located in this file in controller file to use it there?

second question: should I use switch method instead of using if condition each time and to make the code more tidy? And how to use switch method hier?

Thank you

 

var table = this.byId("table");
			table.addEventDelegate({
				onkeydown: function(oEvent) {
					var selectedCheckbox = false;
					var items = table.getItems();

					// Check if any checkbox is selected
					for (var i = 0; i < items.length; i++) {
						var checkbox = items[i].getCells()[0]; // Assuming the checkbox is in the first column
						if (checkbox.getSelected()) {
							selectedCheckbox = true;
							break;

						}

					}
					// Execute the code only if a checkbox is selected
					if (selectedCheckbox) {
						if (oEvent.keyCode === 46) {
							this.onRemoveRowsUi();

						}
						if (oEvent.ctrlKey || oEvent.metaKey) {
							if (oEvent.code === "KeyC") { // Check if the pressed key is 'C'
								this.onCopyPress();
							}
							if (oEvent.code === "KeyV") {
								this.onPastePress();
							}
						}
					}

				}.bind(this)
			});

 

 

Accepted Solutions (0)

Answers (0)