Serialized Dropdown Lists - html

I am struggling with the task of serializing dropdown lists. I am building an app that lets you order items and than you can view the orders. So each order has a list of items assigned to it. I am using AngularJS 1.6.9. This is the html page :
<div ng-app="ShowOrdersApp" ng-controller="mainCtrl" class="container">
<br><br>
<button ng-click="getOrders()"> Show Orders </button>
<br><br>
<table>
<tr>
<th > Orders </th>
</tr>
<tr ng-repeat="x in orderlist">
<td><label> No. {{x.id}} </label><br>
<label> Date and Time : {{x.timestamp}} </label><br>
<button class="btn btn-primary dropdown-toggle" ng-click="getOrderDetails(x.id)"> List of Items
<span class="caret"></span></button><br>
</td>
</tr>
</table>
</div>
On clicking the blue button I want it to show all the items assigned to particular order, but I have trouble creating the dropdown since number of orders may vary and number of items for each order may vary as well. How do I make it work ?

So, do i understood correctly - you want to show items from List of items in dropdown?
Try with this :
HTML:
<table>
<tr>
<th > Orders </th>
</tr>
<tr ng-repeat="x in data">
<td><label> No. {{x.id}} </label><br>
<label> Date and Time : {{x.date}} </label><br>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" ng-click="getOrderDetails(x.id)"> List of Items
<span class="caret"></span></button><br>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" ng-repeat="item in x">
<a class="dropdown-item" style="display: block" ng-repeat="y in item">{{y.name}}</a>
</div></div>
</td>
</tr>
</table>
plunker: http://plnkr.co/edit/LZ8TF0MumSGPOXqFAkLm?p=preview

Related

HTML : Create a dropdown in cell of table

I want to create a table in which one of the cell works as dropdown.
Some data data.field is coming from backend. I want to show it at time of rendering.
Now a fList is also coming from backend, so when someone click of the cell it should open that list as dropdown. I added the below code but it is not showing any dropdown.
<tr class="dropdown" *ngFor="let data of dataList | dataPipe">
<td class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{{data.field}}
<ul class="dropdown-menu" *ngFor="let f of fList">
<li>{{f}}</li>
</ul>
</td>
</tr>
actually you need to loop on dropdown values not dropdown menu
in your case dropdown values are <li>
try this
<tr class="dropdown" *ngFor="let data of dataList | dataPipe">
<td class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{{data.field}}
<ul class="dropdown-menu">
<li *ngFor="let f of fList" (click)="checkValue(f)">{{f}}</li>
</ul>
</td>
</tr>
in your .ts file
public checkValue(value){
console.log(value)
alert(value)
}
this can be a better approach
<select (change)="onChange($event.target.value)">
<option *ngFor="let f of fList">{{f}}</option>
</select>
onChange(value) {
console.log(value);
}
If you want to update the table cell with selected value from dropdown:
<tr class="dropdown" *ngFor="let data of dataList | dataPipe; let i = index;">
<td class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{{data.field}}
<td class="btn btn-primary dropdown-toggle" type="button" data-
toggle="dropdown">{{data.field}}
<ul class="dropdown-menu">
<li *ngFor="let f of fList" (click)="onSelect(f, i)">{{f}}</li>
</ul>
</td>
</td>
onSelect(selectedValue, index){
this.dataList[index].field=selectedValue;
}

How to show and hide buttons with bootstrap and angularjs?

I have a table which contains some data and some buttons which changes according to response and user.
Here's the table.
<div class="form-group">
<div class="col-lg-12 col-md-9">
<table id="basic-datatables" class="table table-bordered" cellspacing="0" width="100">
<thead style="text-align:center">
<tr>
<th rowspan="1" colspan="1" style="width:100px; text-align:center">Employee ID</th>
<th rowspan="1" colspan="1" style="width:100px; text-align:center">Employe Name</th>
<th rowspan="1" colspan="1" style="width:100px; text-align:center">Email</th>
<th rowspan="1" colspan="1" style="width:100px; text-align:center">Department</th>
<th rowspan="1" colspan="1" style="width:100px; text-align:center">Date Created / Joined</th>
<th rowspan="1" colspan="1" style="width:110px; text-align:center">Actions</th>
</tr>
</thead>
<tbody style="text-align:match-parent">
<tr ng-repeat="data in details = (FilterDetails | limitTo:itemsPerPage:(currentPage-1)*itemsPerPage)">
<td style="text-align:center">{{data.Employee.Empid}}</td>
<td style="text-align:center">{{data.Employee.Fname}} {{data.Employee.Lname}}</td>
<td style="text-align:center">{{data.Employee.Email}}</td>
<td style="text-align:center">{{data.Department.DeptName}}</td>
<td style="text-align:center">{{data.Employee.Date_of_join | dateFormat}}</td>
<td style="text-align:center; width:100px">
<div>
<button type="submit" class="btn btn-success pad btn-sm" ng-click="Generate(data)">Generate</button>
<!--<button type="submit" class="btn btn-success pad btn-sm" ng-click="state = true" ng-hide="state">Generate</button>-->
<button type="submit" class="btn btn-warning btn-sm" ng-show="data.UserLogin.Status=='pending'">Pending</button>
<button type="submit" class="btn btn-default btn-sm" ng-show="data.UserLogin.Statuss=='pending'">Retry</button>
</div>
</td>
</tr>
</tbody>
</table>
<p ng-show="details.length == 0">No Users found.</p>
<div class="col-md-8 col-xs-12">
<uib-pagination total-items="totalEmployees" ng-model="currentPage" ng-change="pageChanged()" max-size="maxSize" boundary-links="true" class="pagination" items-per-page="itemsPerPage"></uib-pagination>
</div>
</div>
</div>
What I need to get done is that when the response comes from the JSON data the buttons have to change. Now according to this;
Generate button should show whendata.UserLogin.Status == ''(empty)
Pending button should show when data.UserLogin.Status == 'pending'
Retry button should show when data.UserLogin.Status == 'pending'
How do I achieve this. Help woud be appreciated.
You can use ng-show ng-hide or ng-if like below,
<button class="btn btn-default" ng-show="data.UserLogin.Status == ''">Generate </button>
or
<button class="btn btn-default" ng-hide="data.UserLogin.Status != ''">Generate </button>
or
<button class="btn btn-default" ng-if="data.UserLogin.Status == ''">Generate </button>
You should go for ng-if instead of ng-show or ng-hide. Because in case of ng-show or ng-hide based on the flag the content is loaded in the DOM. so if u try to change the value of flag by using web developer of browser u can be able to see the actual content. But if u go for ng-if, the content is loaded at runtime only when the condition is true. so whenever u want a quicker performance you can go for ng-show or ng-hide but if we want runtime behavior u should use ng-if.
You can write code as below..
<button class="btn btn-default" ng-show="data.UserLogin.Status == ''">Generate </button>
<button class="btn btn-default" ng-show="data.UserLogin.Status == 'pending'">Pending </button>
<button class="btn btn-default" ng-show="data.UserLogin.Status == 'pending'">Retry</button>
We can use ng-if,ng-show,ng-hide like
<button type="submit" class="btn btn-success pad btn-sm" ng-click="Generate(data)" ng-if="!data.UserLogin.Status">Generate</button> <button type="submit" class="btn btn-success pad btn-sm" ng-click="Pending (data)" ng-if="!data.UserLogin.Status">Pending </button>
use ng-if ,it is efficient
Use below code in the success function of the API. This code will run after you get the response and the DOM is created.
$scope.$evalAsync(function(){
$timeout(function() {
// Here set the scope variable and it will work in ng-show
}, 0); // wait...
});
Note: Do not forget to add $timeout in the controller.

is there a special way to put an input field of type checkbox inside a tabledata tag of a table that is present inside an angularjs modal?

here is my modal:
<!-- modal for viewing permissions -->
<div id="modal-user-permissions" class="modal">
<div class="modal-content">
<h4 id="modal-user-title">User Access permissions</h4>
<div class="row">
<table class="hoverable bordered">
<thead>
<tr>
<th class="text-align-center">Allow?</th>
<th class="text-align-center">Page Id</th>
<th class="width-30-pct">page Name</th>
</tr>
</thead>
<tbody >
<tr ng-repeat="d in pages| filter:search">
<td><input type="checkbox" ng-model="d.selected"/></td>
<td class="text-align-center">{{ d.page_id}}</td>
<td>{{d.page_name }}</td>
</tr>
</tbody>
</table>
<div class="input-field col s12">
<a id="btn-update-user" class="waves-effect waves-light btn margin-bottom-1em" ng-click="updateUser()"><i class="material-icons left">edit</i>Save Changes</a>
<a class="modal-action modal-close waves-effect waves-light btn margin-bottom-1em "><i class="material-icons left">close</i>Close</a>
</div>
for testing i'm passing true in every d.selected . i'm not getting the checkbox
here is the output:
Output
i would like to know if i'm not doing something correctly. Any best practices would be appreciated. and finally please tell me a way to get that check box bellow the allow heading in the output table included as picture.
You should use ngChecked instead on ngModel.
Sets the checked attribute on the element, if the expression inside
ngChecked is truthy.
<input type="checkbox" ng-checked="d.selected"/>

Make 2 buttons inside a table cell be next to each other

I have the following code :
<td>
<button class="btn btn-primary btn-xs" ng-click="r.changeView('requests/edit/' + request.id)">
<i class="fa fa-pencil-square-o"></i>
</button>
<button class="btn btn-primary btn-xs" ng-click="r.changeView('requests/edit/' + request.id)">
<i class="fa fa-step-backward"></i>
<i class="fa fa-step-forward"></i>
</button>
</td>
They appear on 2 different lines.
How can I make them appear next to each other on the same line ?
I tried a few things with float and display but without success.
If I add that code in a snippet the buttons are next to each other, so it's hard to reproduce:
<table>
<tr>
<td>
<button class="btn btn-primary btn-xs" ng-click="r.changeView('requests/edit/' + request.id)">
<i class="fa fa-pencil-square-o"></i>Button1
</button>
<button class="btn btn-primary btn-xs" ng-click="r.changeView('requests/edit/' + request.id)">
<i class="fa fa-step-backward"></i>
<i class="fa fa-step-forward"></i>Button2
</button>
</td>
</tr>
</table>
The buttons are already displayed as inline-block.
Maybe the table isn't wide enough; if so, You could try <td style='white-space: nowrap'>.
If you're using Bootstrap, try using classes like "pull-left". This will float both of the buttons left and bring them inline. Also check to be sure nothing is overriding the current display attribute.
<div class="pull-left">...</div>
<div class="pull-right">...</div>
Did you tried display: inline-block;?
However that seems unnecessary because two buttons in the same table cell will appear on the same line.
table,
td,
tr {
border: 1px solid black;
border-collapse: collapse;
}
<table>
<tr>
<td>
<button>Button1</button>
<button>Button2</button>
</td>
</tr>
</table>
What you need is just css display inline code, which can be use to format your button
form {
display: inline;
}
this displays an element as an inline element like span
Please see how to use <table> tag inside in <td> and get all button in line.
<table>
<td>
<table>
<tr>
<td>
<button class="btn btn-primary btn-xs">Add</button>
</td>
<td>
<button class="btn btn-primary btn-xs">Edit</button>
</td>
<td>
<button class="btn btn-primary btn-xs">View</button>
</td>
</tr>
</table>
</td>
</table>

Element not being located by Xpath

I am trying to click on a button in a table row. The relevant HTML code is given below:
<div id="catalogItems" class="col-xs-12">
...
<table class="table table-condensed table-hover">
...
<tbody id="existingItemsList">
<tr id="item_3" class="info item" item_name="vegetables" role="form" item_id="3">
...
</tr>
<tr id="item_4" class="info item" item_name="pizza" role="form" item_id="4">
...
</tr>
<tr id="item_5" class="info item" item_name="Pastries" role="form" item_id="5">
<td>
<button onclick=".." class="btn btn-sm btn-info" type="button"><i class="fa fa-times"></i></button>
</td>
</tr>
<tr id="item_6" class="info item" item_name="Burger" role="form" item_id="6">
...
I want to access the the button in the row with item_name="pastries" to run a test on it with Robot. My Xpath is given below:
xpath=//div[#id='catalogItems']//tr[#item_name=Pastries]//button[#class='btn btn-sm btn-info']
With this, however, the button in the first row (item_name="vegetables") is being selected by the Robot FW. How should I change the xpath to access the item_name="pastries" row? Please help!
I think this is because you have an issue here, please cover Pastries with '', so it looks like 'Pastries'
//tr[#item_name='Pastries']