UI5 has a lot of components that you can use with great out-of-the-box features. With only a few lines of coding you can use these UI5 components. But some more advanced UI5 components require more than just a few lines. For example the ValueHelpDialog requires a lot of coding to use.
For more information about the component:
I needed to use the ValueHelpDialog and I don’t like it to have too much code in my controller. Therefore I created a helper/wrapper object for the ValueHelpDialog. With this helper/wrapper I could just use the ValueHelpDialg with a few lines of code in my controller. But I also made it more generic and easier to use.
To help other developers that want to use this UI5 component I share this helper/wrapper object.
<MultiInput id="valuehelp1" valueHelpRequest="onValueHelpRequest" valueHelpOnly="true" />
this.fields = [
{label:"Column1", key: "Col1", searchable:false, iskey:true,search:true},
{label:"Column2",key:"Col2", searchable:true, iskey:true},
{label:"Column3",key:"Col3", searchable:true,width:"30rem"}
];
this.valuehelp = new ValueHelpHelper(this.getView().getModel(),this.getView().byId("valuehelp1"),this.fields,"Title");
onValueHelpRequest: function() {
var me = this;
this.valuehelp.openValueHelp("/items",
function(selection,ctx){
var oView = this.getView();
console.log("Selection text: " + selection.getText());
console.log("Selection key: " + selection.getKey());
},
function(ctx){
console.log("cancel");
},this);
}
Full code of the controller:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"be/wl/valuehelp/controllers/ValueHelpHelper"
], function (Controller, JSONModel,ValueHelpHelper) {
"use strict";
return Controller.extend("be.wl.valuehelp.controllers.main", {
onInit:function(){
var items = [{Col1:"row1 col1",Col2:"row1 col2",Col3:"row1 col3"},
{Col1:"row2 col1",Col2:"row2 col2",Col3:"row2 col3"}];
this.getView().setModel(new JSONModel({items:items}));
this.fields = [
{label:"Column1", key: "Col1", searchable:false, iskey:true,search:true},
{label:"Column2",key:"Col2", searchable:true, iskey:true},
{label:"Column3",key:"Col3", searchable:true,width:"30rem"}
];
this.valuehelp = new ValueHelpHelper(this.getView().getModel(),this.getView().byId("valuehelp1"),this.fields,"Title");
},
onValueHelpRequest: function() {
var me = this;
this.valuehelp.openValueHelp("/items",
function(selection,ctx){
var oView = this.getView();
console.log("Selection text: " + selection.getText());
console.log("Selection key: " + selection.getKey());
},
function(ctx){
console.log("cancel");
},this);
}
});
});
After search:
After selection you'll get the two keys in the input field:
You can find the full code and demo on plunker:
https://plnkr.co/edit/S4lUbxkCcnR2VJ7APzTb?p=preview
Hope it’s useful!
Kind regards,
Wouter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 |