sap.m.Table - Vertical Scrolling with Fixed Header - sapui5

I have one table having lots of data. Now I want to scroll vertically with table header fixed. can I achieve this?
Here is my code:
onInit: function() {
var data = new JSONModel("Model/data.json");
this.getView().setModel(data);
var otable = this.getView().byId("PlaceIt");
otable.bindItems("/employees", new ColumnListItem({
cells: [
new Text({
text: "{name}"
}),
new Text({
text: "{Physics}"
}),
new Text({
text: "{Chemistry}"
}),
new Text({
text: "{Maths}"
}),
new Text({
text: "{English}"
})
]
}));
otable.setModel(data);
var oScrollContainer = new ScrollContainer({
height: "100px",
vertical: true,
focusable: true,
content: [oTableItems]
});
},
<Table id="PlaceIt">
<columns>
<Column>
<Text text="Student Name" />
</Column>
<Column>
<Text text="Physics" />
</Column>
<Column>
<Text text="Chemistry" />
</Column>
<Column>
<Text text="Maths" />
</Column>
<Column>
<Text text="English" />
</Column>
</columns>
<!-- ... -->
</Table>
I tried using sap.m.ScrollContainer control but I'm not getting anything.
Here is a demo.

As of v1.54, the property sticky is publicly available.
sticky
Defines the section of the sap.m.Table control that remains fixed at the top of the page during vertical scrolling as long as the table is in the viewport.
Once its value is set to "ColumnHeaders", the headers will stay fixed while scrolling.
Be aware that this feature is supported only by modern browsers.
Demo: https://jsbin.com/ticivew/edit?js,output
Property description
Other sticky optionsv1.56 - The syntax for assigning multiple values in XMLView looks as follows:
<Table sticky="HeaderToolbar,InfoToolbar,ColumnHeaders">

Not sure why you don't want to use sap.m.Table, but here's an example nonetheless:
sap.ui.controller("view1.initial", {
onInit : function(oEvent) {
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({
data : [
{
"col1": "at curabitur vestibulum",
"col2": "porttitor pharetra rutrum",
"col3": 93
},
{
"col1": "hendrerit dui fringilla",
"col2": "adipiscing suspendisse lorem",
"col3": 36
},
{
"col1": "placerat vel placerat",
"col2": "suspendisse quis sit",
"col3": 9
},
{
"col1": "sagittis at sed",
"col2": "malesuada aliquam sit",
"col3": 26
},
{
"col1": "donec donec sed",
"col2": "dui tempor nunc",
"col3": 38
},
{
"col1": "sed vitae fringilla",
"col2": "vestibulum pretium dolor",
"col3": 17
},
{
"col1": "scelerisque curabitur orci",
"col2": "sit sollicitudin amet",
"col3": 16
},
{
"col1": "libero lacus pulvinar",
"col2": "lorem velit elit",
"col3": 15
},
{
"col1": "convallis in at",
"col2": "fringilla sagittis magna",
"col3": 35
},
{
"col1": "dolor magna sed",
"col2": "at turpis tortor",
"col3": 3
},
{
"col1": "elit mi tortor",
"col2": "quis aenean turpis",
"col3": 32
},
{
"col1": "ipsum et magna",
"col2": "amet massa aliquam",
"col3": 59
},
{
"col1": "eget magna at",
"col2": "pharetra amet porta",
"col3": 69
},
{
"col1": "magna et scelerisque",
"col2": "aliquam vitae nullam",
"col3": 4
},
{
"col1": "velit etiam odio",
"col2": "lorem lacus magna",
"col3": 28
},
{
"col1": "at scelerisque lorem",
"col2": "facilisis odio dolor",
"col3": 4
},
{
"col1": "amet ipsum massa",
"col2": "sollicitudin sed tortor",
"col3": 54
},
{
"col1": "velit tincidunt massa",
"col2": "risus tortor massa",
"col3": 7
},
{
"col1": "id amet adipiscing",
"col2": "aliquam vitae adipiscing",
"col3": 94
},
{
"col1": "lorem massa lacus",
"col2": "malesuada ac sed",
"col3": 27
}
]
});
this.getView().setModel(oModel);
}
});
sap.ui.xmlview("main", {
viewContent: jQuery("#view1").html()
})
.placeAt("uiArea");
/* extra CSS classes here */
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-libs="sap.ui.commons"></script>
<div id="uiArea"></div>
<script id="view1" type="ui5/xmlview">
<mvc:View
controllerName="view1.initial"
xmlns="sap.ui.commons"
xmlns:l="sap.ui.commons.layout"
xmlns:t="sap.ui.table"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc" >
<t:Table rows="{/data}" visibleRowCount="5">
<t:columns>
<t:Column width="100px">
<t:label><Label text="col1" /></t:label>
<t:template><TextView text="{col1}" /></t:template>
</t:Column>
<t:Column width="100px">
<t:label><Label text="col2" /></t:label>
<t:template><TextView text="{col2}" /></t:template>
</t:Column>
</t:columns>
</t:Table>
</mvc:View>
</script>

You will need two tables.
First table will have only columns and second will contain items to be displayed with empty column headers.
Second table will be the content of ScrollContainer.
demo

To get your own example working, you have to use a ScrollContainer wrapped around the table with vertical="true" and height set to some value. And you need the attribute sticky="ColumnHeaders" on the table itself.
Here is the code from your JS Bin example modified to work:
jQuery.sap.require("sap.m.MessageToast");
// Controller definition
sap.ui.controller("local.controller", {
onInit: function() {
var data = [{
name: "asd",
amount: "100",
currency: "USD",
size: "L"
}, {
name: "asd",
amount: "800",
currency: "INR",
size: "XL"
}, {
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
},{
name: "asd",
amount: "454",
currency: "USD",
size: "S"
}];
var oModel = new sap.ui.model.json.JSONModel(data);
this.getView().setModel(oModel);
var table = this.getView().byId("tableid");
var mytemplate = new sap.m.ColumnListItem({
cells: [
new sap.m.Text({
text: "{name}"
}), new sap.m.Text({
text: "{amount}"
}), new sap.m.Text({
text: "{currency}"
}), new sap.m.Text({
text: "{size}"
})
]
});
table.bindAggregation("items",{
path: "/",
template : mytemplate
});
}
});
// Instantiate the View, assign a model and display
var oView = sap.ui.xmlview({
viewContent: jQuery('#view1').html()
});
oView.placeAt('content');
<!DOCTYPE HTML>
<html>
<head>
<meta name="description" content="temp">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="UTF-8">
<title></title>
<script id="sap-ui-bootstrap" type="text/javascript" src="https://sapui5.ap1.hana.ondemand.com/resources/sap-ui-cachebuster/sap-ui-core.js" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m" data-sap-ui-xx-bindingSyntax="complex">
</script>
<!-- XML-based view definition -->
<script id="view1" type="sapui5/xmlview">
<mvc:View controllerName="local.controller" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
<App>
<Page title="My View" id="page">
<ScrollContainer
height="200px"
vertical="true"
>
<Table id="tableid" sticky="ColumnHeaders">
<columns>
<Column>
<Text text="column1" />
</Column>
<Column>
<Text text="column2" />
</Column>
<Column>
<Text text="column3" />
</Column>
<Column>
<Text text="column4" />
</Column>
</columns>
</Table>
</ScrollContainer>
</Page>
</App>
</mvc:View>
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>

Related

Vue.js Phone field not required, but not letting me submit if empty

I would like to be able to submit the following form without the phone field being required.
However, I would still like the phone field to be validated with regex before being able to be submit if a user inputs a phone number value.
So if blank, submit, ELSE check that it's valid before submitting. I thought had worked this out, but apparently not...
Any help is very much appreciated!
const app = Vue.createApp({
data() {
return {
currentYear: new Date().getFullYear(),
now: new Date().toISOString(),
imgSrc:
"",
contact: {
firstName: "",
lastName: "",
email: "",
phone: "",
address: "",
city: "",
state: "",
zip: "",
checked: false,
},
states: [
{
name: "Alabama",
abr: "AL",
},
{
name: "Alaska",
abr: "AK",
},
{
name: "American Samoa",
abr: "AS",
},
{
name: "Arizona",
abr: "AZ",
},
{
name: "Arkansas",
abr: "AR",
},
{
name: "California",
abr: "CA",
},
{
name: "Colorado",
abr: "CO",
},
{
name: "Connecticut",
abr: "CT",
},
{
name: "Delaware",
abr: "DE",
},
{
name: "District Of Columbia",
abr: "DC",
},
{
name: "Federated States Of Micronesia",
abr: "FM",
},
{
name: "Florida",
abr: "FL",
},
{
name: "Georgia",
abr: "GA",
},
{
name: "Guam",
abr: "GU",
},
{
name: "Hawaii",
abr: "HI",
},
{
name: "Idaho",
abr: "ID",
},
{
name: "Illinois",
abr: "IL",
},
{
name: "Indiana",
abr: "IN",
},
{
name: "Iowa",
abr: "IA",
},
{
name: "Kansas",
abr: "KS",
},
{
name: "Kentucky",
abr: "KY",
},
{
name: "Louisiana",
abr: "LA",
},
{
name: "Maine",
abr: "ME",
},
{
name: "Marshall Islands",
abr: "MH",
},
{
name: "Maryland",
abr: "MD",
},
{
name: "Massachusetts",
abr: "MA",
},
{
name: "Michigan",
abr: "MI",
},
{
name: "Minnesota",
abr: "MN",
},
{
name: "Mississippi",
abr: "MS",
},
{
name: "Missouri",
abr: "MO",
},
{
name: "Montana",
abr: "MT",
},
{
name: "Nebraska",
abr: "NE",
},
{
name: "Nevada",
abr: "NV",
},
{
name: "New Hampshire",
abr: "NH",
},
{
name: "New Jersey",
abr: "NJ",
},
{
name: "New Mexico",
abr: "NM",
},
{
name: "New York",
abr: "NY",
},
{
name: "North Carolina",
abr: "NC",
},
{
name: "North Dakota",
abr: "ND",
},
{
name: "Northern Mariana Islands",
abr: "MP",
},
{
name: "Ohio",
abr: "OH",
},
{
name: "Oklahoma",
abr: "OK",
},
{
name: "Oregon",
abr: "OR",
},
{
name: "Palau",
abr: "PW",
},
{
name: "Pennsylvania",
abr: "PA",
},
{
name: "Puerto Rico",
abr: "PR",
},
{
name: "Rhode Island",
abr: "RI",
},
{
name: "South Carolina",
abr: "SC",
},
{
name: "South Dakota",
abr: "SD",
},
{
name: "Tennessee",
abr: "TN",
},
{
name: "Texas",
abr: "TX",
},
{
name: "Utah",
abr: "UT",
},
{
name: "Vermont",
abr: "VT",
},
{
name: "Virgin Islands",
abr: "VI",
},
{
name: "Virginia",
abr: "VA",
},
{
name: "Washington",
abr: "WA",
},
{
name: "West Virginia",
abr: "WV",
},
{
name: "Wisconsin",
abr: "WI",
},
{
name: "Wyoming",
abr: "WY",
},
],
};
},
methods: {
submitForm(e) {
const isValid =
this.contact.firstName &&
this.contact.lastName &&
this.contact.email &&
this.validEmail(this.contact.email) &&
this.validPhone(this.contact.phone) &&
this.validZip(this.contact.zip);
e.target.classList.add("was-validated");
if (!isValid) {
e.preventDefault();
}
},
validEmail: function (email) {
const re =
/^(([^<>()[\]\\.,;:\s#"]+(\.[^<>()[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
},
validPhone: function (phone) {
const re = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
return re.test(phone);
},
validZip: function (zip) {
const re = /^\d{5}(?:[-\s]\d{4})?$/;
return re.test(zip);
},
},
});
app.mount("#awApp");
<!DOCTYPE html>
<html lang="en" class="vh-100">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<!-- Bootstrap 5 CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<!-- /Bootstrap 5 CSS-->
<style>
main > .container {
padding: 60px 15px 0;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vue#3.0.11"></script>
</head>
<body>
<div id="awApp" class="d-flex flex-column vh-100">
<!-- FIXED NAVBAR AND/OR HEADER -->
<header>
<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img :src="imgSrc" alt="logo" width="120" />
</a>
</div>
</nav>
</header>
<!-- / HEADER/NAVBAR -->
<!-- MAIN CONTENT -->
<main role="main" class="flex-shrink-0">
<div class="container">
<div class="row my-5">
<div class="col-md-7">
<img
src="http://placehold.it/1200x400"
alt="hero image"
class="img-fluid"
/>
<h2 class="mt-3">Headline goes here...</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Corporis dolore eaque, facere id molestias perspiciatis sit?
</p>
<ul>
<li>benefit 1</li>
<li>benefit 2</li>
<li>benefit 3</li>
</ul>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad
aliquid assumenda consectetur deleniti est ipsam nemo nobis
officiis quasi, quod!
</p>
</div>
<div class="col-md-5">
<div class="card shadow p-3">
<!--<img class="card-img-top rz-card-img-top" src="http://placehold.it/400x100" alt="Card image cap">-->
<div class="card-body">
<h5 class="card-title">Headline</h5>
<p class="card-text">
Some quick example text to build on the card title and make
up the bulk of the card's content.
</p>
<form
novalidate
class="needs-validation"
name="mainForm"
#submit="submitForm"
method="post"
>
<div class="row mb-2">
<div class="col-md-6 mb-3">
<label for="firstname" class="form-label mb-0"
>First Name*</label
>
<input
id="firstname"
type="text"
name="firstname"
class="form-control"
v-model="contact.firstName"
id="awValid"
required
/>
<div class="valid-feedback">Looks good!</div>
<div class="invalid-feedback">
Please enter a first name.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="lastname" class="form-label mb-0"
>Last Name*</label
>
<input
id="lastname"
type="text"
name="lastname"
class="form-control"
v-model="contact.lastName"
required
/>
<div class="invalid-feedback">
Please enter a last name.
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="email" class="form-label mb-0"
>Email Address*</label
>
<input
id="email"
type="text"
name="email"
class="form-control"
v-model="contact.email"
pattern="^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*#[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,20})$"
required
/>
<div class="invalid-feedback">
Please enter a valid email.
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="phone" class="form-label mb-0"
>Phone
</label>
<input
id="phone"
type="text"
name="phone"
class="form-control"
pattern="^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"
v-model="contact.phone"
/>
<div class="invalid-feedback">
Please enter a valid phone number.
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="address1" class="form-label mb-0"
>Street Address
</label>
<input
id="address1"
type="text"
name="address1"
class="form-control"
v-model="contact.address"
/>
</div>
</div>
<div class="row mb-2">
<div class="col-md-5 mb-3">
<label for="city" class="form-label mb-0">City</label>
<input
id="city"
type="text"
name="city"
class="form-control"
v-model="contact.city"
/>
</div>
<div class="col-md-3 mb-3">
<label for="state" class="form-label mb-0">State</label>
<select
id="state"
name="state"
v-model="contact.state"
class="form-select"
>
<option>##state##</option>
<option
v-for="state in states"
v-bind:value="state.abr"
>
{{state.name}}
</option>
</select>
</div>
<div class="col-md-4 mb-3">
<label for="zip" class="form-label mb-0"
>Zip Code</label
>
<input
id="zip"
type="text"
name="zip"
class="form-control"
v-model="contact.zip"
pattern="^\d{5}(?:[-\s]\d{4})?$"
/>
<div class="invalid-feedback">
Please enter a valid zip code.
</div>
</div>
</div>
<div class="row mb-2">
<div class="col">
<div class="form-check">
<input
id="checkbox1"
type="checkbox"
class="form-check-input"
name="check-me-out"
v-model="contact.checked"
/>
<label for="checkbox1" class="form-check-label"
>Check me out</label
>
<div></div>
</div>
</div>
</div>
<input
type="submit"
class="btn btn-primary"
value="Submit"
/>
<div>
<small class="form-text text-muted">
<em>* Denotes a required field.</em>
</small>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- /MAIN CONTENT -->
<!-- FOOTER -->
<footer class="footer mt-auto py-3 bg-light text-center">
<div class="container">
<span class="text-muted"
>© {{currentYear}} |
Privacy Policy |
Legal</span
>
</div>
</footer>
<!-- /FOOTER -->
</div>
<!--Bootstrap 5 JS-->
<script
src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"
></script>
<!--/Bootstrap 5 JS-->
</body>
</html>
You could add a condition to the isValid Boolean that checks whether the phone field is empty:
export default {
methods: {
submitForm(e) {
const isValid =
this.contact.firstName &&
this.contact.lastName &&
this.contact.email &&
this.validEmail(this.contact.email) &&
👇
(!this.contact.phone || this.validPhone(this.contact.phone)) &&
this.validZip(this.contact.zip);
//...
}
}
}
const app = Vue.createApp({
data() {
return {
currentYear: new Date().getFullYear(),
now: new Date().toISOString(),
imgSrc:
"",
contact: {
firstName: "",
lastName: "",
email: "",
phone: "",
address: "",
city: "",
state: "",
zip: "",
checked: false,
},
states: [
{
name: "Alabama",
abr: "AL",
},
{
name: "Alaska",
abr: "AK",
},
{
name: "American Samoa",
abr: "AS",
},
{
name: "Arizona",
abr: "AZ",
},
{
name: "Arkansas",
abr: "AR",
},
{
name: "California",
abr: "CA",
},
{
name: "Colorado",
abr: "CO",
},
{
name: "Connecticut",
abr: "CT",
},
{
name: "Delaware",
abr: "DE",
},
{
name: "District Of Columbia",
abr: "DC",
},
{
name: "Federated States Of Micronesia",
abr: "FM",
},
{
name: "Florida",
abr: "FL",
},
{
name: "Georgia",
abr: "GA",
},
{
name: "Guam",
abr: "GU",
},
{
name: "Hawaii",
abr: "HI",
},
{
name: "Idaho",
abr: "ID",
},
{
name: "Illinois",
abr: "IL",
},
{
name: "Indiana",
abr: "IN",
},
{
name: "Iowa",
abr: "IA",
},
{
name: "Kansas",
abr: "KS",
},
{
name: "Kentucky",
abr: "KY",
},
{
name: "Louisiana",
abr: "LA",
},
{
name: "Maine",
abr: "ME",
},
{
name: "Marshall Islands",
abr: "MH",
},
{
name: "Maryland",
abr: "MD",
},
{
name: "Massachusetts",
abr: "MA",
},
{
name: "Michigan",
abr: "MI",
},
{
name: "Minnesota",
abr: "MN",
},
{
name: "Mississippi",
abr: "MS",
},
{
name: "Missouri",
abr: "MO",
},
{
name: "Montana",
abr: "MT",
},
{
name: "Nebraska",
abr: "NE",
},
{
name: "Nevada",
abr: "NV",
},
{
name: "New Hampshire",
abr: "NH",
},
{
name: "New Jersey",
abr: "NJ",
},
{
name: "New Mexico",
abr: "NM",
},
{
name: "New York",
abr: "NY",
},
{
name: "North Carolina",
abr: "NC",
},
{
name: "North Dakota",
abr: "ND",
},
{
name: "Northern Mariana Islands",
abr: "MP",
},
{
name: "Ohio",
abr: "OH",
},
{
name: "Oklahoma",
abr: "OK",
},
{
name: "Oregon",
abr: "OR",
},
{
name: "Palau",
abr: "PW",
},
{
name: "Pennsylvania",
abr: "PA",
},
{
name: "Puerto Rico",
abr: "PR",
},
{
name: "Rhode Island",
abr: "RI",
},
{
name: "South Carolina",
abr: "SC",
},
{
name: "South Dakota",
abr: "SD",
},
{
name: "Tennessee",
abr: "TN",
},
{
name: "Texas",
abr: "TX",
},
{
name: "Utah",
abr: "UT",
},
{
name: "Vermont",
abr: "VT",
},
{
name: "Virgin Islands",
abr: "VI",
},
{
name: "Virginia",
abr: "VA",
},
{
name: "Washington",
abr: "WA",
},
{
name: "West Virginia",
abr: "WV",
},
{
name: "Wisconsin",
abr: "WI",
},
{
name: "Wyoming",
abr: "WY",
},
],
};
},
methods: {
submitForm(e) {
const isValid =
this.contact.firstName &&
this.contact.lastName &&
this.contact.email &&
this.validEmail(this.contact.email) &&
(!this.contact.phone || this.validPhone(this.contact.phone)) &&
this.validZip(this.contact.zip);
e.target.classList.add("was-validated");
if (!isValid) {
e.preventDefault();
}
},
validEmail: function (email) {
const re =
/^(([^<>()[\]\\.,;:\s#"]+(\.[^<>()[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
},
validPhone: function (phone) {
const re = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
return re.test(phone);
},
validZip: function (zip) {
const re = /^\d{5}(?:[-\s]\d{4})?$/;
return re.test(zip);
},
},
});
app.mount("#awApp");
<!DOCTYPE html>
<html lang="en" class="vh-100">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<!-- Bootstrap 5 CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<!-- /Bootstrap 5 CSS-->
<style>
main > .container {
padding: 60px 15px 0;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vue#3.0.11"></script>
</head>
<body>
<div id="awApp" class="d-flex flex-column vh-100">
<!-- FIXED NAVBAR AND/OR HEADER -->
<header>
<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img :src="imgSrc" alt="logo" width="120" />
</a>
</div>
</nav>
</header>
<!-- / HEADER/NAVBAR -->
<!-- MAIN CONTENT -->
<main role="main" class="flex-shrink-0">
<div class="container">
<div class="row my-5">
<div class="col-md-7">
<img
src="http://placehold.it/1200x400"
alt="hero image"
class="img-fluid"
/>
<h2 class="mt-3">Headline goes here...</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Corporis dolore eaque, facere id molestias perspiciatis sit?
</p>
<ul>
<li>benefit 1</li>
<li>benefit 2</li>
<li>benefit 3</li>
</ul>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad
aliquid assumenda consectetur deleniti est ipsam nemo nobis
officiis quasi, quod!
</p>
</div>
<div class="col-md-5">
<div class="card shadow p-3">
<!--<img class="card-img-top rz-card-img-top" src="http://placehold.it/400x100" alt="Card image cap">-->
<div class="card-body">
<h5 class="card-title">Headline</h5>
<p class="card-text">
Some quick example text to build on the card title and make
up the bulk of the card's content.
</p>
<form
novalidate
class="needs-validation"
name="mainForm"
#submit="submitForm"
method="post"
>
<div class="row mb-2">
<div class="col-md-6 mb-3">
<label for="firstname" class="form-label mb-0"
>First Name*</label
>
<input
id="firstname"
type="text"
name="firstname"
class="form-control"
v-model="contact.firstName"
id="awValid"
required
/>
<div class="valid-feedback">Looks good!</div>
<div class="invalid-feedback">
Please enter a first name.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="lastname" class="form-label mb-0"
>Last Name*</label
>
<input
id="lastname"
type="text"
name="lastname"
class="form-control"
v-model="contact.lastName"
required
/>
<div class="invalid-feedback">
Please enter a last name.
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="email" class="form-label mb-0"
>Email Address*</label
>
<input
id="email"
type="text"
name="email"
class="form-control"
v-model="contact.email"
pattern="^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*#[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,20})$"
required
/>
<div class="invalid-feedback">
Please enter a valid email.
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="phone" class="form-label mb-0"
>Phone
</label>
<input
id="phone"
type="text"
name="phone"
class="form-control"
pattern="^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"
v-model="contact.phone"
/>
<div class="invalid-feedback">
Please enter a valid phone number.
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<label for="address1" class="form-label mb-0"
>Street Address
</label>
<input
id="address1"
type="text"
name="address1"
class="form-control"
v-model="contact.address"
/>
</div>
</div>
<div class="row mb-2">
<div class="col-md-5 mb-3">
<label for="city" class="form-label mb-0">City</label>
<input
id="city"
type="text"
name="city"
class="form-control"
v-model="contact.city"
/>
</div>
<div class="col-md-3 mb-3">
<label for="state" class="form-label mb-0">State</label>
<select
id="state"
name="state"
v-model="contact.state"
class="form-select"
>
<option>##state##</option>
<option
v-for="state in states"
v-bind:value="state.abr"
>
{{state.name}}
</option>
</select>
</div>
<div class="col-md-4 mb-3">
<label for="zip" class="form-label mb-0"
>Zip Code</label
>
<input
id="zip"
type="text"
name="zip"
class="form-control"
v-model="contact.zip"
pattern="^\d{5}(?:[-\s]\d{4})?$"
/>
<div class="invalid-feedback">
Please enter a valid zip code.
</div>
</div>
</div>
<div class="row mb-2">
<div class="col">
<div class="form-check">
<input
id="checkbox1"
type="checkbox"
class="form-check-input"
name="check-me-out"
v-model="contact.checked"
/>
<label for="checkbox1" class="form-check-label"
>Check me out</label
>
<div></div>
</div>
</div>
</div>
<input
type="submit"
class="btn btn-primary"
value="Submit"
/>
<div>
<small class="form-text text-muted">
<em>* Denotes a required field.</em>
</small>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- /MAIN CONTENT -->
<!-- FOOTER -->
<footer class="footer mt-auto py-3 bg-light text-center">
<div class="container">
<span class="text-muted"
>© {{currentYear}} |
Privacy Policy |
Legal</span
>
</div>
</footer>
<!-- /FOOTER -->
</div>
<!--Bootstrap 5 JS-->
<script
src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"
></script>
<!--/Bootstrap 5 JS-->
</body>
</html>

How to get the aggregated values of an OData (V2) property?

I want to display a chart (sap.viz.ui5.controls.VizFrame) that visualizes data from an OData Service. However, the data of the service has to be manipulated. See the example below:
Main.view.xml
<mvc:View controllerName="demo.chart.controller.Main" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
<Shell id="shell">
<App id="app">
<pages>
<Page id="page" title="Chart Demo">
<content></content>
</Page>
</pages>
</App>
</Shell>
</mvc:View>
Chart.fragment.xml
<c:FragmentDefinition xmlns:c="sap.ui.core" xmlns:viz="sap.viz.ui5.controls" xmlns:viz.data="sap.viz.ui5.data"
xmlns:viz.feeds="sap.viz.ui5.controls.common.feeds">
<viz:VizFrame uiConfig="{applicationSet:'fiori'}" vizType='donut'>
<viz:dataset>
<viz.data:FlattenedDataset data="{manipulatedData>/}">
<viz.data:dimensions>
<viz.data:DimensionDefinition name="Gender" value="{manipulatedData>gender}"/>
</viz.data:dimensions>
<viz.data:measures>
<viz.data:MeasureDefinition name="Amount" value="{manipulatedData>amount}"/>
</viz.data:measures>
</viz.data:FlattenedDataset>
</viz:dataset>
<viz:feeds>
<viz.feeds:FeedItem uid="color" type="Dimension" values="Gender"/>
<viz.feeds:FeedItem uid="size" type="Measure" values="Amount"/>
</viz:feeds>
</viz:VizFrame>
</c:FragmentDefinition>
Main.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel",
"sap/ui/core/Fragment"
], function (Controller, JSONModel, Fragment) {
"use strict";
return Controller.extend("demo.chart.controller.Main", {
onInit: function () {
const mDefault = this.getOwnerComponent().getModel();
const mManipulatedData = new JSONModel([{
gender: "F",
amount: 0
}, {
gender: "M",
amount: 0
}, {
gender: "X",
amount: 12
}]);
this.getView().setModel(mManipulatedData, "manipulatedData");
console.log(this.getView().getModel("manipulatedData"));
mDefault.read("/ContactSet", {
success: oData => {
const aManipulatedData = mManipulatedData.getData();
oData.results.forEach(entry => {
aManipulatedData.forEach(type => {
if (entry.Sex === type.gender) {
type.amount++
}
})
});
Fragment.load({
name: "demo.chart.view.Chart",
controller: this
}).then(oFragment => {
this.getView().addDependent(oFragment);
this.byId("page").addContent(oFragment);
});
}
})
}
});
});
Structure of the service (GWSAMPLE_BASIC/ContactSet)
{
"d": {
"results": [
{
"__metadata": {
"id": "https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/ContactSet(guid'0050568c-901d-1eda-bcae-e8394de7e116')",
"uri": "https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/ContactSet(guid'0050568c-901d-1eda-bcae-e8394de7e116')",
"type": "GWSAMPLE_BASIC.Contact"
},
"Address": {
"__metadata": {
"type": "GWSAMPLE_BASIC.CT_Address"
},
"City": "Walldorf",
"PostalCode": "69190",
"Street": "Robert-Koch-Straße",
"Building": "1",
"Country": "DE",
"AddressType": "02"
},
"ContactGuid": "0050568c-901d-1eda-bcae-e8394de7e116",
"BusinessPartnerID": "0100000000",
"Title": "",
"FirstName": "Karl",
"MiddleName": "",
"LastName": "Müller",
"Nickname": "",
"Initials": "",
"Sex": "M",
"PhoneNumber": "0622734567",
"FaxNumber": "0622734004",
"EmailAddress": "do.not.reply#sap.com",
"Language": "EN",
"DateOfBirth": null,
"ToBusinessPartner": {
"__deferred": {
"uri": "https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/ContactSet(guid'0050568c-901d-1eda-bcae-e8394de7e116')/ToBusinessPartner"
}
}
}
]
}
}
So, as you can see, I'm only interested in the aggregated values of the Sex property. My current solution is to loop through all the entries of the entity set and increase the property in a custom JSON model. This is not only very inperformant because you do the heavy-lifting on the client side, it also requires you to know all the possible values for the data displayed in the chart right away. Is there a way to do this with OData queries or do I have to create a new entity set with the comulated data in my SAP system?
OData should be able to count and group, as described in this quesiton: OData v4 groupby with $count
But I doubt your SAP OData Service will, most of the time, those services do not implement the full OData specification.
You can improve your js by not using two nested for loops but something like this:
mGender = {};
oData.results.forEach(entry => {
if (!mGender[entry.Sex])
{mGender[entry.Sex] = 0
}
mGender[entry.Sex]++
});

Dynamic Table binding

Please suggest. Table binding does not work.
Model Data and may change:
​{ "TestCloudEnvRO": [ { "pipelineName": "RP1", "cycles": [ "cy1", "cycle1", "RP1cy2", "cyc2", "crCycle" ] }, { "pipelineName": "RP2", "cycles": [ "BP1-c2", "bp2-cy" ] }, { "pipelineName": "RPlocal", "cycles": [ "cyclelocal" ] }, { "pipelineName": "rp1234", "cycles": [ "cyclert" ] }, { "pipelineName": "RPTEST", "cycles": [ "BPTEST1" ] }, { "pipelineName": "rp123", "cycles": [ "cytr" ] } ] }
View
<Table id="idtrlAllPipelines" alternateRowColors="true">
<columns>
<Column demandPopin="true" minScreenWidth="Tablet">
<Text text="Release Pipeline Cycles"/>
</Column>
</columns>
Controller
var oTemplate = new sap.m.ColumnListItem({ cells: [ new sap.m.Text({ text: "{getHist>pipelineName}" }) ] }); this.byId("idtrlAllPipelines").setModel(oModelEnv, "getHist");
this.byId("idtrlAllPipelines").bindAggregation("items", { path: "getHist>/TestCloudEnvRO", template: oTemplate, templateShareable: true } );
It does not load any items in the table.
But this works at View. I have to replace this with /TestCloudEnvRO with selected key of Icon tab filter, so the above should work. Please suggest.
<Table items="{path: 'getHist>/TestCloudEnvRO'}" id="idtrlAllPipelines" alternateRowColors="true">
For the binding you suggested, your dataset may need to be modified a bit in order to achieve the requirement. PFB the code.
Controller
loadDataSet: function () {
var oMasterModel = this.getView().getModel("oMasterModel");
var oDataSet = [{
"IconTabName": "Env1",
"Table": [{
"name": "Person1",
"runs": ["10", "20"]
}, {
"name": "Person2",
"runs": ["0", "2"]
}]
}, {
"IconTabName": "Env2",
"Table": [{
"name": "Person3",
"runs": ["5", "25"]
}, {
"name": "Person4",
"runs": ["20", "12"]
}]
}];
oMasterModel.setData({
allFilters: oDataSet
});
oMasterModel.refresh(true);
}
View
<IconTabBar items="{oMasterModel>/allFilters}">
<items>
<IconTabFilter text="{oMasterModel>IconTabName}">
<Table items="{oMasterModel>Table}">
<columns>
<Column>
<Label text="Name"/>
</Column>
<Column >
<Label text="Runs"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{oMasterModel>name}"/>
<Select items="{oMasterModel>runs}">
<core:Item text="{oMasterModel>}"/>
</Select>
</cells>
</ColumnListItem>
</items>
</Table>
</IconTabFilter>
</items>
</IconTabBar>

The filter doesnt work with one input character on b-table

i have a b-table with a filter, but the filter doesn't work when i search by one character, in my case, by the ID, but, if i introduce 2 or more numbers this work.
i check the example on bootstrap-vue and this work searching by one number, but i cant find why in my code this not work as i expected.
<div id="app">
<span label-for="search">search: </span>
<input id="search" type="text" v-model="filter" placeholder="type by search">
{{ this.filter }}
<b-table
class="mt-2"
:filter="filter"
:fields="fields"
:items="items">
</b-table>
</div>
window.onload = () => {
new Vue({
el: '#app',
data() {
return {
filter: null,
fields: [
{
key: 'isoqf_id',
label: '#'
},
{
key: 'name',
label: 'Name'
},
{
key: 'references',
label: 'references id'
}
],
items: [
{
"isoqf_id": 1,
"cerqual": {
"explanation": "Suspendisse eget ligula blandit, dignissim neque at, luctus nunc. Nulla eros odio, fringilla et diam ut, maximus euismod nibh.",
"option": "0"
},
"name": "finding #1",
"references": ["4a5f2a", "4a5f2f"],
"organization": "7b9c88ec182ca383",
"project_id": "5d84d6bc2b711a1a2eba93ea",
"id": "5d84ee422b711a1a2eba9507",
"cerqual_option": "0"
}, {
"isoqf_id": 2,
"cerqual": {
"explanation": "",
"option": "0"
},
"name": "finding #2",
"references": ["4a5f3b", "4a5f37"],
"organization": "7b9c88ec182ca383",
"project_id": "5d84d6bc2b711a1a2eba93ea",
"id": "5d850b3c2b711a1a2eba956f",
"cerqual_option": "0"
}, {
"isoqf_id": 3,
"cerqual": {
"explanation": "",
"option": "3"
},
"name": "finding #3",
"references": ["4a5f3b", "4a5f28"],
"organization": "7b9c88ec182ca383",
"project_id": "5d84d6bc2b711a1a2eba93ea",
"id": "5d8517a72b711a1a2eba9679",
"cerqual_option": "3"
}]
}
},
methods: {
}
})
}
the url for test https://codepen.io/damian-garrido/pen/aboemNG
i expect i can search by the isoqf_id field, what i'm doing wrong?
The default search algorithm searches ALL fields in the items table (not just visible data). It matches by looking for anything that contains the filter string. So if you type in the digit 1 it will show all records that have the character 1 in any fields.
To limit to just certain fields, set the prop filter-included-fields to an array containing the top level property names (field names) that you want to restrict the search to. If you want to limit to just isoqf_id, then set :filter-included-fields=['isoqf_id']". To limit filtering to isoqf_id and references set `:filter-included-fields=['isoqf_id', 'references']"
See https://bootstrap-vue.js.org/docs/components/table#built-in-filtering-options

Controlling zindex on leaflet icons layer

In below I am trying to bring the green circle to the front by clicking the button. How can I achieve this?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" >
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
</head>
<body>
<button onclick="ccsdf()">Click me</button>
<div id="map" style="width: 100%; height: 90vh"></div>
<script>
var map;
var layer1;
var layer2;
function ccsdf() {
layer1.bringToFront();
}
$(document).ready(function(){
map = L.map('map').setView([0, 0], 14);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
layer1 = L.geoJson({ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [ 0, 0.0005 ]}}]}, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: L.icon({ iconUrl: 'https://upload.wikimedia.org/wikipedia/commons/5/52/Small_red_circle.png' }) });
}
}).addTo(map);
layer2 = L.geoJson({ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [ 0, 0 ]}}]}, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: L.icon({ iconUrl: 'https://upload.wikimedia.org/wikipedia/commons/e/e7/Blue_1.png' }) });
}
}).addTo(map);
});
</script>
</body>
</html>
Any ideas?
Cheers
Below text is because stack overflow wants me to write more :-)
Lorem ipsum dolor sit amet, interdum est eu. A tellus condimentum hendrerit enim, ligula fusce vitae, leo et fusce mauris lorem suscipit scelerisque. Vel arcu, non vestibulum suspendisse non lectus magnis suspendisse, aliquam magna commodo. Nascetur eleifend at faucibus faucibus, nulla fringilla, mauris ultrices posuere in
Not sure exactly why featureGroup.bringToFront() does not seem to work in your case. It may be that it works only on vector shapes, which do have individual bringToFront() method as well, on the contrary of markers.
Anyway, you can simply use layerGroup.eachLayer() method to apply a zIndexOffset to each marker (you may need to check if the layer is an L.Marker if your group has many layers). You can simply use the marker.setZIndexOffset() method to achieve this.
function ccsdf() {
//layer1.bringToFront();
layer1.eachLayer(function (layer) {
layer.setZIndexOffset(1000);
});
}
Demo on Plunker: http://plnkr.co/edit/lQLNiR5HwX4vT84vBLAC?p=preview
This plugin will do the trick: leaflet.forceZIndex.js
// Force zIndex of Leaflet
(function(global){
var MarkerMixin = {
_updateZIndex: function (offset) {
this._icon.style.zIndex = this.options.forceZIndex ? (this.options.forceZIndex + (this.options.zIndexOffset || 0)) : (this._zIndex + offset);
},
setForceZIndex: function(forceZIndex) {
this.options.forceZIndex = forceZIndex ? forceZIndex : null;
}
};
if (global) global.include(MarkerMixin);
})(L.Marker);
To use:
var aMarker = L.marker([lat, lon], {
icon: icon,
title: title,
forceZIndex: <Value> // This is forceZIndex value
})
forceZIndex declaration will assure that ZIndex will be always set from aMarker.options.forceZIndex
Update it somewhere to re-force ZIndex value
aMarker.setForceZIndex(<New Value>)
Or setForceZIndex(null) to automatical zIndex state:
aMarker.setForceZIndex(null);
By the end of the day, if no forceZIndex option declared, Marker will work with normal behaviour.