I have a table with button. What I need is when I click on the button in the table , a modal diplay with its value.
My problem is how to pass the table's value to the modal. Can any one help me, here is the code
<div style="margin-top: 50px" class="col-md-12">
<div class="card">
<div class="card-block">
<div class="horizontal-scroll">
<table class="table table-condensed">
<thead>
<tr>
<th>Titre</th>
<th>Description</th>
<th>Durée (jours)</th>
<th>Coût (TalanCoin)</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of formations">
<td>{{ item[1] }}</td>
<td style="margin-left: 4cm;">
<button type="button" class="btn btn-info btn-icon" (click)="smModal.show()"><i class="ion-information"></i></button>
</td>
<td>{{ item[3] }}</td>
<td>{{ item[4] }}</td>
<td >
<button class="btn btn-success" (click)="clicked(item[4],lgModal)">Participer</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Small modal -->
<div bsModal #smModal="bs-modal" class="modal fade" tabindex="-1"
role="dialog" aria-labelledby="mySmallModalLabel" aria-
hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button class="close" aria-label="Close"
(click)="smModal.hide()">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Description</h4>
</div>
<div class="modal-body" style="color: black;">
<!--here I want to display the value selected from the table-->
</div>
<div class="modal-footer">
<button class="btn btn-primary confirm-btn"
(click)="smModal.hide()">Save changes</button>
</div>
</div>
You could make a function in your component which opens the modal like this:
...
export class AppComponent {
#ViewChild('smModal') smModal;
currentItem;
...
openModal(item: any) {
this.currentItem = item;
this.smModal.show();
}
}
Then instead of smModal.show() you can call openModal(item). In the modal, you can then access {{ currentItem }} the same way you access item in the table.
Related
I tried to show added product details after i clicked shopping cart icon or if i added any one product same like https://designmodo.com/shopping-cart-ui/. Initially no need to show the" Your Cart Items" added product box.I do not know how to do like that.If any one know please help to find the solutions.
addtocart-dir.ts:
<div class="card text-center">
<div class="card-header">
Your Cart Items
<button type="button" class="btn btn-sm btn-warning float-right">
Total items <span class="badge badge-light">{{cart.cartItemsList.length}}</span>
</button>
<button type="button" class="btn btn-sm btn-danger mr-2 float-right" (click)="emptyCart()" *ngIf="cart.cartItemsList && cart.cartTotal">
Empty Cart
</button>
</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Price</th>
<th scope="col">Qty</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<tr>
</tr>
<tr *ngFor="let itm of cart.cartItemsList ">
<td class="text-left">{{itm.name}}</td>
<td>{{itm.price/itm.qty}} x</td>
<td class="w30">
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<button class="btn btn-info" type="button" (click)="changeQty(itm.pid,1,'')">+</button>
</div>
<input type="text" class="form-control text-center" value="{{itm.qty}}" #qtyRef (keyup)="changeQty(itm.pid,qtyRef.value,'replace')" >
<div class="input-group-append">
<button class="btn btn-danger" type="button" (click)="changeQty(itm.pid,-1,'')">-</button>
</div>
</div>
</td>
<td>{{itm.price}}</td>
</tr>
</tbody>
</table>
<a routerLink = "/billing" class="btn btn-sm btn-primary" *ngIf="cart.cartItemsList && cart.cartTotal">Checkout</a>
</div>
<div class="card-footer text-muted font-weight-bold">
Total : Rs. {{cart.cartTotal}}
</div>
</div>
Demo: https://stackblitz.com/edit/angular-selvam-ecommerce-task-btjqde?file=src%2Fapp%2Fdirectives%2Faddtocart.dir.ts
Change in cart.service.ts
public cartItemsList: any = [];
change in products.pages.ts
<div class="row">
<div [ngClass]="cart.cartItemsList.length == 0 ? 'col-md-12' : 'col-md-7'">
<productslist-dir (refresh)="ref($event)" [allProductList]="products.data [searchedText]="searchText" [sortingBy]="sortOption"></productslist-dir>
</div>
<div class="col-md-5" *ngIf="cart.cartItemsList.length > 0">
<cart></cart>
</div>
change in productslist.dir.ts
ngOnInit(){
this.sortByOption = 'product_name';
this.cart.allItems = this.__allprdts;
this.cart.storeItems();
}
addToCart(productId,productQty){
this.cart.addToCart(productId,productQty,'');
this.refresh.emit(true);
}
please check and let me know..
this is the html file, I want to get the id of the particular student click on and delete the student using the popup modal
<div style="margin-top: 50px;">
<table datatable="ng" class="row-border hover" [dtOptions]="dtOptions" [dtTrigger]="dtTrigger">
<thead>
<tr>
<th>S/N</th>
<th>Full Name</th>
<th>Class</th>
<th>Sex</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let student of students; let i = index">
<td>{{i+1}}</td>
<td><a [routerLink]="['/view-student', student.id]" >{{student.lastName + ' ' + student.firstName}}</a></td>
<td>{{student.grade.name}}</td>
<td>{{student.sex.name}}</td>
<td><a [routerLink]="['/edit-student', student.id]" class="btn btn-primary" >Edit</a></td>
<td><a data-toggle="modal" data-target="#myModal" class="btn btn-danger">Delete</a></td>
</tr>
</tbody>
</table>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Warning</h4>
</div>
<div class="modal-body">
Are you sure you want to delete..
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
<button type="button" (click)="" data-dismiss="modal" class="btn btn-primary">Yes</button>
</div>
</div>
</div>
</div>
this is the delete function I have in the component to use for deleting the student I click on. thank you for your help in advance
delete(id){
this.studentService.delete(id).subscribe(() => {
this.students.splice(id, 1);
this.loadAllStudents();
});}
Simply save a current student id in component property.
html(table):
...
<td><a (click)="setId(student.id)" data-toggle="modal" data-target="#myModal" class="btn btn-danger">Delete</a></td>
...
ts:
public id = ''
setId(id) {
this.id = id
}
html(modal):
...
<button type="button" (click)="delete(id)" data-dismiss="modal" class="btn btn-primary">Yes</button>
...
i'm new in angular2 + typescript. And i need realize confirmation modal by click on button in table
This is table
<div style="margin-top: 10px">
<table id="recruitersTable" class="table table-striped center" [ngBusy]="data">
<tr>
<th>{{ 'RECRUITER_NAME_AND_SURNANE_COLUMN' | translate }}</th>
<th>{{ 'RECRUITER_CODE_COLUMN' | translate }}</th>
<th>{{ 'RECRUITER_ACTION_DOLUMN' | translate}}</th>
<th></th>
</tr>
<tr *ngFor="let recruiter of recruiters">
<td>{{ recruiter.Name }}</td>
<td>{{ recruiter.Code }}</td>
<td>
<a class="btn btn-xs btn-default" data-target="#confirm" role="button" data-toggle="modal">
<span class="glyphicon glyphicon-ban-circle"></span>
</a>
</td>
<td></td>
</tr>
</table>
</div>
This is confirmation modal
<div id="confirm" class="modal fade in" aria-labelledby="modallabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove"></span></button>
<h3 id="modalLabael">Block recruiter</h3>
</div>
<div class="modal-body">
<h3 id="modalLabael">Are you sure that you want block this recruiter?</h3>
</div>
<div class="modal-footer">
<button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button class="btn btn-success" (click)="BlockRecruiter(recruiter.code)">Block</button>
</div>
</div>
</div>
And i need implement function by click 'success' on confirm modal, but data in another div. Can someone explain me?
You could either use EventEmitter if your modal component is contained in the parent component - Check here --> https://angular.io/docs/ts/latest/api/core/index/EventEmitter-class.html
Or you could use a service that returns a subject as an observable. The parent component can subscribe to the observable while the modal alerts the service on confirmation. Check how the alert.service has been written and used here --> Angular 2: Displaying icons in navbar on authentication
I got a table which repeats a delete button for each and every member. The confirmation button does work when I don't use the modal, however if i use the Modal, the first row only gets deleted.
As I researched, it could be that since the delete is getting repeated, its value stays for the first row.
Table HTML Code:
<table class="table table-bordered" id="customForms" ng-show="showMembers">
<thead><tr> <th> ID </th> <th>Name</th> <th>Surname</th> <th>Date Of Affiliation</th> <th>Status</th> <th>Email</th> <th>Summary</th></tr></thead>
<tbody>
<tr ng-repeat="member in members">
<td>{{member.memberID}}</td>
<td>{{member.name}}</td>
<td>{{member.surname}}</td>
<td>{{member.dateOfAffiliation}}</td>
<td>{{member.status}}</td>
<td>{{member.email}}</td>
<td>{{member.summary}}</td>
<td><button class="btn btn-primary" data-toggle="modal" data-target="#myModal"> DELETE </button>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete Confirmation</h4>
</div>
<div class="modal-body">
Are you sure you wish to delete this row?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="deleteMember(member)" data-dismiss="modal">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
AngularJS Code:
$scope.deleteMember = function(member) {
$http.post('model/deleteMember.php', member).success(function(data) {
$scope.getMember();
});
}
Want to show modal window in the center of webbrowser and show user information from my bootstrap td row which user clicked. Can you help me out? Below find my current code. I can't find the way
Here below you see i made tr as modal and put data-id to 1:
....
<tbody>
#For Each item In Model.Transports
Dim currentItem = item
#<tr data-toggle="modal" data-id="1" data-target="#orderModal">
<td class="col-lg-4 text-center vert-align_td">#item.Name</td>
<td class="col-lg-4 text-center vert-align_td">#item.Surname</td>
<td class="col-lg-4 text-center vert-align_td">#item.Age</td>
....
Heres my modal window where i want to put all information:
#<div id="orderModal" class="modal hide fade" role="dialog" aria-labelledby="orderModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
Information for lp number:
Name:
Surname:
Age:
</div>
<div id="orderDetails" class="modal-body"></div>
<div id="orderItems" class="modal-body"></div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
and here is my JS:
$(function () {
$('#orderModal').modal({
keyboard: true,
backdrop: "static",
show: false,
}).on('show', function () {
var getIdFromRow = $(event.target).closest('tr').data('Lp');
//make your ajax call populate items or what even you need
$(this).find('#orderDetails').html($('<b> Information for LP: ' + getIdFromRow + '</b>'))
});
});
EDITED (for further duscussions:)
...
#For Each item In Model.Transports
Dim currentItem = item
#<tr data-toggle="modal" data-target="#myModal" data-id="12">
<td class="col-lg-1">#item.Lp</td>
<td class="col-lg-1">#item.Name</td>
Modal:
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body" id="orderDetails">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
JS:
$('#myModal').on('show.bs.modal', function (event) {
//var getIdFromRow = $(event.relatedTarget).attr('data-id');
// if you wnat to take the text of the first cell
var getIdFromRow1 = $(event.relatedTarget).find('td:first-child').text();
var getIdFromRow2 = $(event.relatedTarget).find('td:second-child').text();
$(this).find('#orderDetails').html($('<b> Information for LP: ' + getIdFromRow1 + '</b>'))
$(this).find('#orderDetails').html($('<b> Information for DataPrzyjazdu: ' + getIdFromRow2 + '</b>'))
});
EDIT2:
$('#myModal').on('show.bs.modal', function (event) {
var getIdFromRow1 = $(event.relatedTarget).find('td:first-child').text();
$(this).find('#orderDetails').html($('<b> Information for Lp: ' + getIdFromRow1 + '</b>'))
var getIdFromRow2 = $(event.relatedTarget).find('td:nth-child(2)').text();
$(this).find('#orderDetails').html($('<b> Information for Data przyjazdu: ' + getIdFromRow2 + '</b>'))
});
Modal:
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body" id="orderDetails">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
table:
#<tr data-toggle="modal" data-target="#myModal" data-id="12">
<td class="col-lg-1 text-center vert-align_td">#item.Lp</td>
<td class="col-lg-1 text-center vert-align_td">#item.DataPrzyjazdu</td>
You have some problems with your code:
You should use show.bs.modal event instead of show event. docs.
You should use $(event.relatedTarget) (return the tr) instead of $(event.target) (return the modal).
$('#myModal').on('show.bs.modal', function (event) {
//var getIdFromRow = $(event.relatedTarget).attr('data-id');
// if you wnat to take the text of the first cell
var getIdFromRow = $(event.relatedTarget).find('td:first-child').text();
$(this).find('#orderDetails').html($('<b> Information for LP: ' + getIdFromRow + '</b>'))
});
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<table class="table">
<tr>
<th>ID</th>
<th>Name</th>
<th>Col 3</th>
<th>Col 4</th>
</tr>
<tr data-toggle="modal" data-target="#myModal" data-id="12">
<td>ID is 12</td>
<td>Col 2</td>
<td>Col 3</td>
<td>Col 4</td>
</tr>
</table>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body" id="orderDetails">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>