Skip to content

Instantly share code, notes, and snippets.

@gbvaibhav
Created February 3, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbvaibhav/1e65a12ba0f6a0e4025d3d21cff2159e to your computer and use it in GitHub Desktop.
Save gbvaibhav/1e65a12ba0f6a0e4025d3d21cff2159e to your computer and use it in GitHub Desktop.
Sapui5 sap.m.Table to get a notification if the filtered items of a table give only 1 item. https://jsbin.com/sinaci
<!DOCTYPE html>
<html><head>
<meta name="description" content="UI5 List example with local JSON model" />
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<title>SAPUI5 Example gbvaibhav</title>
<!-- Load UI5, select gold reflection theme and the "commons" and "table" control libraries -->
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m,sap.ui.layout"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-theme="sap_bluecrystal"></script>
<script>
var table = new sap.m.Table({columns:[
new sap.m.Column({header:[new sap.m.Label({text:"FirstName"})]})
],});
var template = new sap.m.ColumnListItem({cells:[
new sap.m.Text({text:"{first}"})
]})
table.bindItems("/results",template);
// creating some data for binding
var data = {
results:[
{ first:"R" },
{ first:"Vaibhav" },
{ first:"Anoop" },
{ first:"Jk" },
{ first:"Pachu" },
{ first:"ABS" } ]
};
var model = new sap.ui.model.json.JSONModel(data);
table.setModel(model);
var input = new sap.m.Input({placeHolder:"Please input your filter query"});
var filterButton = new sap.m.Button({text:"Filter",press:function(){
var fil = input.getValue();
var filter = [new sap.ui.model.Filter("first", sap.ui.model.FilterOperator.Contains,fil)];
table.getBinding("items").filter(filter);
if( table.getBinding("items").getLength() === 1){
alert("only 1 item after filter ")
}
}});
var Hbox = new sap.m.HBox({items:[
input,filterButton
]});
var page = new sap.m.Page({
title:"SAPUI5 List Example",
content:[
Hbox,
table
]
});
// finally place the App into the UI
var app = new sap.m.App({
pages: [page]
}).placeAt("content");
</script>
</head>
<body>
<div id='content'></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment