How can I click on an HTML row then show the values of the row in input texts - angularjs

How can I click on an HTML row then show the values of the row in input texts to able the user to edit them.
in controller :
$scope.data = [];
$scope.selectedMember = { Code: "", Latin: "", Local: "" }; //new property
$scope.showInEdit = function (member)
{
$scope.selectedMember = member;
}
in ng-repeat :
<table border="1" ng-hide="Hide">
<thead>
<tr>
<th>Code</th>
<th>Latin Description</th>
<th>Local Description</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="c in Contracts | filter:Code | filter:Latin | filter:Local track by $index">
<td>{{c.Staff_Type_Code}}</td>
<td>{{c.L_Desc}}</td>
<td>{{c.A_Desc}}</td>
<!--<td><input type="button" value="Edit" ng-click="Edit(c)"/> </td>-->
</tr>
</tbody>
</table>
In HTML :
<table>
<tr>
<td>Code</td>
<td><input type="text" size="10" pattern="^[a-zA-Z0-9]+$" title="Alphnumeric" autofocus ng-model="selectedMember.Code.Staff_Type_Code"></td>
</tr>
<tr>
<td>Latin Description</td>
<td><input type="text" size="35" ng-model="Latin.L_Desc"></td>
</tr>
<tr>
<td>Local Description</td>
<td><input type="text" size="35" ng-model="Local.A_Desc"></td>
</tr>
Thanks lot

You just need to update your scope variables in function like
$scope.Latin.L_Desc = c.example;
After that you'll see these values in input fields.

If you want to show values in this code
<table>
<tr>
<td>Code</td>
<td><input type="text" size="10" pattern="^[a-zA-Z0-9]+$" title="Alphnumeric" autofocus ng-model="selectedMember.Code.Staff_Type_Code"></td>
</tr>
<tr>
<td>Latin Description</td>
<td><input type="text" size="35" ng-model="Latin.L_Desc"></td>
</tr>
<tr>
<td>Local Description</td>
<td><input type="text" size="35" ng-model="Local.A_Desc"></td>
</tr>
Then your object must be like this :
$scope.selectedMember = { Code: "", Latin: {A_Desc:""}, Local: {L_Desc:""} };
And in controller function
$scope.showInEdit = function (member)
{
$scope.selectedMember.Latin.L_Desc = member;
}

Related

Filter one way binding - inline filter

So I have this
<input type="text" ng-model="search" class="form-control">
And
<tr ng-repeat="city in cities | filter: search">
<td>{{city.description}}</td>
<td>{{(countries | filter : {id:city.idCountry}:true)[0].description}}</td>
</tr>
I have a table and I use the syntax above to display a property (description) which is in a different array of objects (countries), because they have a foreign key relation in the DB. I want to be able to filter by this property (description in countries) existent in this foreign object. I don't know how to accomplish this.
So far I can only filter by properties that are inside the city object.
Example:
city = {
id: 55,
code: "C4589",
description: "NYC",
idCountry: 35
}
country = {
id: 15,
description: "US"
}
The generated HTML is
<input type="text" ng-model="searchF" class="form-control">
<table>
<thead>
<tr>
<th>Description</th>
<th>Code</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td class="ng-binding">Dallas</td>
<td class="ng-binding">C458</td>
<td class="ng-binding">US</td>
</tr>
<tr>
<td class="ng-binding">NYC</td>
<td class="ng-binding">N4596</td>
<td class="ng-binding">US</td>
</tr>
</tbody>
</table>

How to show pop up in table validation in angular JS

what should I use for displaying faculty Id is needed pop up box during validation of data inside tables. If I am not entering faculty Id then it shouldn't get added and should show that message.
<table ng-form name="myForm">
<tr>
<td>Faculty ID</td>
<td><input type="text" ng-model="faculty.id" required/></td>
</tr>
<tr>
<td>Faculty Name:</td>
<td><input type="text" ng-model="faculty.name" /></td>
</tr>
<tr>
<td>Faculty Salary:</td>
<td><input type="text" ng-model="faculty.salary" /></td>
</tr>
<tr>
<td colspan="2"><button ng-disabled="myForm.$invalid" ng-click="addfaculty(faculty)">ADD</button></td>
</tr>
</table>
you made a typo:)
ng-disbaled
should be ng-disabled
You can do this
<table ng-form name="myForm">
<tr>
<td>Faculty ID</td>
<td ><input type="text" ng-model="faculty.id" required/></td>
</tr>
<tr>
<td>Faculty Name:</td>
<td><input type="text" ng-model="faculty.name" /></td>
</tr>
<tr>
<td>Faculty Salary:</td>
<td><input type="text" ng-model="faculty.salary" /></td>
</tr>
<tr>
<td colspan="2"><button ng-disabled="myForm.$invalid" ng-click="addfaculty(faculty)">ADD</button></td>
</tr>
</table>

How to select only filtered table data in angularjs?

This is My Code:
<div>
<input type="search" class="form-control" placeholder="Search Student" ng- model="stdsearch" />
</div>
<table class="table" >
<thead>
<tr>
<th><input type="checkbox" ng-model="master"></th>
<th>Admission No</th>
<th>Student Name</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in ClassStudents | filter:stdsearch">
<td><input id="checkSlave" type="checkbox" ng-checked="master" ng-model="student.isselected" aria-label="Slave input"></td>
<td>{{student.Admission_no}}</td>
<td>{{student.First_Name}} {{student.MiddleName}} {{student.Last_Name}}</td>
</tr>
</tbody>
</table>
Here My Query is : I want to Check Only Filtered Rows in table When i check Master Checkbox(th).but here selected all rows of table when i remove Search text in search box. Pls Suggest me. 10Q.
Here what I have tried :
The plunker is here
I have created sample data as per HTML.
Use 'last1' as search value. You will get an idea.
$scope.ClassStudents = [{Admission_no :1,First_Name:'first1' ,MiddleName: 'middle1',Last_Name:'last1'},
{Admission_no :1,First_Name:'first2' ,MiddleName: 'middle1',Last_Name:'last1'},
{Admission_no :1,First_Name:'first3' ,MiddleName: 'middle2',Last_Name:'last2'},
{Admission_no :1,First_Name:'first4' ,MiddleName: 'middle3',Last_Name:'last1'}
];
$scope.checkUncheck = function(masterCheck){
angular.forEach( $scope.ClassStudents,function(value,key){
if(masterCheck && !$scope.stdsearch){
value.master = true;
}else{
value.master = false;
}
})
}
filter('customFilter',function(){
return function(input,masterCheck,stdsearch){
angular.forEach(input,function(value,key){
if(stdsearch){
if(masterCheck){
value.master = true;
}else{
value.master = false;
}
}
})
return input;
}
})
<body ng-controller="testCtrl">
<input type="text" ng-model="stdsearch">
<table class="table" >
<thead>
<tr>
<th><input type="checkbox" ng-model="master" ng-change = "checkUncheck(master) "></th>
<th>Admission No</th>
<th>Student Name</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in ClassStudents |filter : stdsearch| customFilter : master : stdsearch">
<td><input id="checkSlave" type="checkbox" ng-checked="student.master" ng-model="student.isselected" aria-label="Slave input"></td>
<td>{{student.Admission_no}}</td>
<td>{{student.First_Name}} {{student.MiddleName}} {{student.Last_Name}}</td>
</tr>
</tbody>
</table>
</body>
Please let me know if there is any error.

How to calculate a dynamic value with ng-repeat for a nested object property in AngularJs

I want to calculate taxes in relation with a user-input that correspond to the price.
I have no problem when I don't use ng-repeat. But I can't figure out how to make it works with ng-repeat. For information, the code below refers to an invoice controller where I add items to the invoice.
Here is what I have:
Controller
App.controller('FacturesSoloController', function($scope, $stateParams, Facture ) {
$scope.factureId = $stateParams.factureId;
Facture.get({ id: $stateParams.factureId }, function(data) {
$scope.facture = data;
$scope.ajouterItem = function(){
$scope.facture.items.push({});
}
});
$scope.calculTps = function() {
$scope.item.tps = $scope.item.prix*5/100;
};
$scope.calculTvq = function() {
$scope.item.tvq = $scope.item.prix*9.975/100;
};
$scope.calculGrandTotal = function() {
$scope.item.grandtotal = parseFloat($scope.item.prix)+parseFloat($scope.item.tps)+parseFloat($scope.item.tvq);
};
});
Here is my HTML file
<table class="table">
<thead>
<tr>
<th><strong>Description</strong></th>
<th class="text-right"><strong>Prix</strong></th>
<th class="text-right"><strong>TPS</strong></th>
<th class="text-right"><strong>TVQ</strong></th>
<th class="text-right"><strong>Grand Total</strong></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in facture.items">
<td class="bold" width="50%">
<input type="text" class="form-control" name="description" id="description" ng-model="item.description"></td>
<td class="text-right">
<input type="text" class="form-control" name="prix" id="prix" ng-model="item.prix"></td>
<td class="text-right">
<input type="text" class="form-control" name="tps" id="tps" ng-model="item.tps" value="{{calculTps()}}"></td>
<td class="text-right">
<input type="text" class="form-control" name="tvq" id="tvq" ng-model="item.tvq" value="{{calculTvq()}}"></td>
<td class="text-right">
<input type="text" class="form-control" name="grandtotal" id="grandtotal" ng-model="item.grandtotal" value="{{calculGrandTotal()}}">
</td>
</tr>
<tr>
<td class="bold"></td>
<td class="text-right"></td>
<td class="text-right"></td>
<td class="text-right"></td>
<td class="text-right">Grand Total</td>
</tr>
</tbody>
</table>
And here is what {{facture.items | json}} returns
[
{
"id": 1,
"facture_id": 10200,
"description": "Item numéro 1",
"prix": "15.00",
"tps": "0.75",
"tvq": "1.50",
"grandtotal": "17.25",
"created_at": "2015-02-21 15:07:18",
"updated_at": "2015-02-21 15:07:18"
},
{
"id": 2,
"facture_id": 10200,
"description": "Deuxième item quoi",
"prix": "135.00",
"tps": "6.75",
"tvq": "13.47",
"grandtotal": "155.22",
"created_at": "2015-02-21 15:07:18",
"updated_at": "2015-02-21 15:07:18"
}
]
So, I would like the "tps" and the "tvq" to calculate automaticly when I enter a number in the "prix" input. I wonder what is wrong.
In your javascript you still need to refer to 'item' as part of the 'facture' array. The controller doesn't know what '$scope.item' is. You can use '$index' to call a function which will do your calculations for each element in the array.
App.controller('FacturesSoloController', function($scope, $stateParams, Facture ) {
$scope.factureId = $stateParams.factureId;
Facture.get({ id: $stateParams.factureId }, function(data) {
$scope.facture = data;
$scope.ajouterItem = function(){
$scope.facture.items.push({});
}
});
$scope.calculTps = function(i) {
$scope.facture.items[i].tps = $scope.facture.items[i].prix*5/100;
};
$scope.calculTvq = function(i) {
$scope.facture.items[i].tvq = $scope.facture.items[i].prix*9.975/100;
};
$scope.calculGrandTotal = function(i) {
$scope.facture.items[i].grandtotal = parseFloat($scope.facture.items[i].prix)+parseFloat($scope.facture.items[i].tps)+parseFloat($scope.facture.items[i].tvq);
};
$scope.doCalculations = function(i) {
$scope.calculTvq(i);
$scope.calculTps(i);
$scope.calculGrandTotal(i);
}
});
and your HTML
<table class="table">
<thead>
<tr>
<th><strong>Description</strong></th>
<th class="text-right"><strong>Prix</strong></th>
<th class="text-right"><strong>TPS</strong></th>
<th class="text-right"><strong>TVQ</strong></th>
<th class="text-right"><strong>Grand Total</strong></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in facture.items">
<td class="bold" width="50%">
<input type="text" class="form-control" name="description" id="description" ng-model="item.description"></td>
<td class="text-right">
<input type="text" class="form-control" name="prix" id="prix" ng-model="item.prix" ng-change="doCalculations($index)></td>
<td class="text-right">
<input type="text" class="form-control" name="tps" id="tps" ng-model="item.tps"></td>
<td class="text-right">
<input type="text" class="form-control" name="tvq" id="tvq" ng-model="item.tvq"></td>
<td class="text-right">
<input type="text" class="form-control" name="grandtotal" id="grandtotal" ng-model="item.grandtotal">
</td>
</tr>
<tr>
<td class="bold"></td>
<td class="text-right"></td>
<td class="text-right"></td>
<td class="text-right"></td>
<td class="text-right">Grand Total</td>
</tr>
</tbody>
</table>
https://docs.angularjs.org/api/ng/directive/ngRepeat
https://docs.angularjs.org/api/ng/directive/ngChange
UPDATE:
You should also use ngChange to call both calculation functions each time the 'prix' is updated

Filtering static data in AngularJS

I have a column which is populated based on a value in the JSON. I would like to filter the data based on the value I have displayed based on the value in the JSON. How can I achieve this?
JSON Data:
{
flip: {
image: "image1"
zone: "sing_tel"
},
environment: "development",
location: "sing11",
}
<table>
<thead>
<tr>
<td colspan="6">
<input type="text" class="pull-right input-large global-search" placeholder="Search .." data-ng-model="searchNetwork.$">
</td>
</tr>
<tr>
<th class="input-search">
<input type="text" class="span12" data-ng-model="srchId" data-ng-change="delaySearch('id', srchId)" placeholder="ID .." />
</th>
<th colspan="2" class="input-search">
<input type="text" class="span12" data-ng-model="srchLink" data-ng-change="delaySrch('href', searchLink)" placeholder="Net Link" />
</th>
<th class="input-search">
<input type="text" class="span12" data-ng-model="srchLocation" data-ng-change="delaySearch('loc', srchLocation)" placeholder="Location" />
</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="network in networkData | orderBy:predicate:reverse | filter:searchNetwork">
<td>{{network.id}}</td>
<td>{{network.location}}</td>
<td>{{network.privacy}}</td>
</tr>
</tbody>
</table>
Flip element in the above JSON is received only for some nodes to which I display the value as FlipMe in my UI. I would like to filter my data based on this column.

Resources