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;
}
Related
I'm trying to create a toggle for the only input you see inside of the span so I could hide it once I click the "Edit" button again. Any idea on how to make it work?
HTML:
<h2>Universities</h2>
<ul *ngFor="let item of items; let i = index">
<li>
{{ item }}
<button
type="button"
class="btn btn-default"
style="background-color: #ffe4b5"
(click)="editIndex = i"
>
Edit
</button>
<span>
<input *ngIf="editIndex === i" />
</span>
<span>
<button
type="button"
class="btn btn-default"
style="background-color: #90ee90"
>
Save
</button>
</span>
</li>
</ul>
TS:
items: string[] = [];
editIndex: number | undefined;
showInput: boolean = false;
showData(index: any) {
console.log(this.items[index]);
}
(I created ShowData just to test if the index of the item works in the console when I click it)
You need to set the editIndex on click:
<!-- component template -->
<button type="button" (click)="setEditIndex(i)" class="btn btn-default" style="background-color: #ffe4b5">
// component
setEditIndex(index: number): void {
if (this.editIndex === index) {
this.editIndex = null;
}
else {
this.editIndex = index;
}
}
Your condition check in the template for editIndex === i should work after that.
You can toggle the editIndex in the click function
In html
<button
type="button"
class="btn btn-default"
style="background-color: #ffe4b5"
(click)="toggle()"
>
Edit
</button>
<span>
<input *ngIf="editIndex" />
</span>
In .ts
editIndex = false;
toggle() {
this.editIndex = !this.editIndex
}
I want to make an editable manual with ng-if in AngularJS but when I click on one of the table cells, all the table cells in Jumlah Pembelian display the input form.
before click:
after clicking on one cell:
My question: how to display form input when I click one cell
My HTML code:
<td ng-if="kons_makanan == 0" class="middle-vertical text-center"
ng-click="change_jumlah(bu.id)">{{jumlah_makanan}}</td>
<td ng-if="kons_makanan == 1">
<div class="form-inline">
<input type="text" class="form-control" number-masking
ng-model="jumlah_makanan" style="width:auto;">
<a class="btn btn-flat btn-sm btn-success"
ng-click="update_jumlah_makanan(bu.id)" title="Tambah">
<i class='fa fa-plus'></i>
</a>
</div>
</td>
My AngularJS code:
$scope.change_jumlah = function(no) {
$scope.kons_makanan = 1;
}
$scope.update_jumlah_makanan = function(no) {
$scope.kons_makanan = 0;
}
Sorry everyone, I tried and was successful
HTML code:
<td ng-if="kons_makanan != $index" class="middle-vertical text-center"
ng-click="change_jumlah($index)">{{jumlah_makanan}}</td>
<td ng-if="kons_makanan == $index">
<div class="form-inline">
<input type="text" class="form-control" number-masking
ng-model="jumlah_makanan" style="width:auto;">
<a class="btn btn-flat btn-sm btn-success"
ng-click="update_jumlah_makanan(bu.id)" title="Tambah">
<i class='fa fa-plus'></i>
</a>
</div>
AngularJS code:
$scope.change_jumlah = function(no) {
$scope.kons_makanan = no;
}
$scope.update_jumlah_makanan = function(no) {
$scope.kons_makanan = -1;
}
Thanks all for trying to help me
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
I don't know why after adding the if statement a margin/space between my action links disappears. I'm pretty sure that a HTML looks the same with or without #if (User.IsInRole("Admin")) (from the admin perspective). I'm using bootstrap 4.1.
<section id="sec5">
<div class="container pt-5">
<div class="table-responsive-sm mb-3">
<table class="table">
<tr>
<th>Name</th>
<th class="text-right">Action</th>
</tr>
#foreach (var u in Model)
{
<tr>
<td>#u.Name</td>
<td class="text-right">
#if (User.IsInRole("Admin"))
{
#Html.ActionLink("Edit", "Edit", new { id = u.SpecialityId }, new { #class = "btn btn-secondary" })
#Html.ActionLink("Delete", "Delete", new { id = u.SpecialityId }, new { #class = "btn btn-danger" })
}
</td>
</tr>
}
</table>
</div>
</div>
</section>
E:
https://jsfiddle.net/xoduf1sp/5/
In your example both the second link follows the first link immediately.
If i add a linebreak between them in the html the usual inline element gap appears.
Maybe your if clause does somehow elimitate whitespace/linebreak characters between the two links?
Was:
<a class="btn btn-secondary" href="#">Edit</a><a class="btn btn-danger" href="#">Delete</a>
Should be:
<a class="btn btn-secondary" href="#">Edit</a>
<a class="btn btn-danger" href="#">Delete</a>
See http://jsfiddle.net/xoduf1sp/7.
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.