Get values from ng-repeater - angularjs

I am trying to get the id value from each row in a ng-repeater into an input type="text" to be able to save the sort order of the table. But I don't know how to just extract the id, so I get the full vlaue of the list.
The table looks like this:
<table class="table table-striped">
<thead>
<tr>
<th class="position"></th>
<th>Specification Title</th>
<th>Last modified</th>
<th class="right">Used in</th>
</tr>
</thead>
<tbody ui-sortable="sortableOptions" ng-model="specsList">
<tr ng-repeat="spec in specsList">
<td class="position draggable"></td>
<td>{{spec.title}}</td>
<td>{{spec.lastModified}}</td>
<td class="right color_green"><strong>{{spec.usedIn}}</strong> of 12 products</td>
</tr>
</tbody>
</table>
And the input:
<input type="text" id="tableSortOrder" value="{{specsList}}">
Current value in the input text:
[{"id":"123","title":"Brand","lastModified":"2012-08-14","usedIn":"7"},{"id":"789","title":"Amount","lastModified":"2010-07-22","usedIn":"5"},{"id":"456","title":"ISBN","lastModified":"2010-02-24","usedIn":"2"}]
What I want to achieve:
123, 789, 456
Thanks for any help!

Is this what you want?:
<input type="text" id="tableSortOrder" value="{{ specsList.map(function(item){return item.id;}).join() }}" />
You could do that in a filter too, like this:
<input type="text" id="tableSortOrder" value="{{ specsList | splitIds }}" />
app.filter('splitIds', function() {
return function(ArrayWithIds) {
return ArrayWithIds.map(function(item){return item.id;}).join();
};
});
I've made this jsfiddle so that you can see how it works: http://jsfiddle.net/d5ye9mus/2/

Related

How to check the rows of ng-repeat values in angular js

How to access the rows of ng-repeat of array of arrays?
in jsp:
I have one json array object which have content of table.
and another array object table header.
so below I used to implement it. But I have one situation that if col1 data is Y then I need to display one check box. How to check that..
<body ng-app="myApp" ng-controller="mainCtrl">
<div class="table-container">
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<th lr-drag-src="headers" lr-drop-target="headers" ng-repeat="col in columns" st-sort="{{col}}">{{col}}</th>
</tr>
<tr>
<th>
<input st-search="firstName" placeholder="search for firstname" class="input-sm form-control" type="search"/>
</th>
<th colspan="4">
<input st-search placeholder="global search" class="input-sm form-control" type="search"/>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rowCollection">
<td ng-repeat="col in columns**>{{row[col]}}</**td>
</tr>
</tbody>
</table>
</div>
<div ng-show="isLoading" class="loading-indicator"></div>
</body>
Single array:
')" id = "checkExport" value = "{{result.TX_ID}}">
{{result.TX_ID}}
{{result.value2}}
You can use rowCollection[1].columns with foreach to find if some value in columns contains Y. But the better way just use ng-show="col === Y" as attribute to your checkbox. Or ng-hide if you need to hide it.

how to shows last index input value tag... ng-repeat

how to shows input value in last index in ng-repeat but its shows everyrow item... i want only last index user enter payment amount please anyone help me this highly appreciated
<table class="table display table-hover table-bordered product-overview mb-10" id="support_table">
<thead>
<tr class="bg-info">
<th class="col-md-4">Shirka Name</th>
<th class="col-md-1">Approvals</th>
<th class="col-md-2">CompanyRate</th>
<th class="col-md-1">Mofa Upload Date</th>
<th class="col-md-2">Payment</th>
<th class="col-md-1">Balance</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in VisaPaymentList">
<td>{{item.ShirkaName}}</td>
<td>{{item.approvals}}</td>
<td>{{item.CompanyRate}}</td>
<td>{{item.DateField}}</td>
<td><input ng-change="BalanceMinus()"
ng-model="item.PaymentReceived" autocomplete="off"
id="payment" class="form-control input-height"
placeholder="Payment" type="text">
</td>
<td>{{item.Balance}}</td>
</tr>
</tbody>
</table>
Use the ng-if directive with the $last property of the ng-repeat item scope:
<tr ng-repeat="item in VisaPaymentList">
<td>{{item.ShirkaName}}</td>
<td>{{item.approvals}}</td>
<td>{{item.CompanyRate}}</td>
<td>{{item.DateField}}</td>
<td>
<̶i̶n̶p̶u̶t̶ ̶n̶g̶-̶c̶h̶a̶n̶g̶e̶=̶"̶B̶a̶l̶a̶n̶c̶e̶M̶i̶n̶u̶s̶(̶)̶"̶
<input ng-if="$last" ng-change="BalanceMinus()"
ng-model="item.PaymentReceived" autocomplete="off"
̶i̶d̶=̶"̶p̶a̶y̶m̶e̶n̶t̶"̶ ̶c̶l̶a̶s̶s̶=̶"̶f̶o̶r̶m̶-̶c̶o̶n̶t̶r̶o̶l̶ ̶i̶n̶p̶u̶t̶-̶h̶e̶i̶g̶h̶t̶"̶ ̶
name="payment" class="form-control input-height"
placeholder="Payment" type="text">
</td>
<td>{{item.Balance}}</td>
</tr>
When $last is true, the <input> element will be added. Otherwise the <td> element will be empty.
For more information, see
AngularJS ng-repeat Directive API Reference - Overview

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

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;
}

Why cannot I add new list in a table in angularJS 1.x?

I have example code below where I am supposed to create a list of items.
<div ng-hide="listTrigger">
<!--FIRST TABLE-->
<table class="table table-bordered table-striped">
<thead>
<tr>
<th sortable="code" class="sortable">
Product Name
</th>
<th sortable="placed" class="sortable">
Qty
</th>
<th class="st-sort-disable th-dropdown">
Price
</th>
<th sortable='total.value' class="sortable">
Split
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr grid-item>
<td width="40%">
<select class="form-control" ng-model="prod.uid">
<option selected disabled>Select Product</option>
<option ng-repeat="product in products | orderBy : 'name'" ng-value="product.uid" >{{product.name}}</option>
</select>
</td>
<td width="20%">
<input type="number" min="0" ng-model="prod.qty" class="form-control">
</td>
<td width="20%">
<input type="number" min="0" ng-model="prod.price" class="form-control">
</td>
<td width="10%">
<input type="number" min="1" max="100" ng-model="prod.split" class="form-control">
</td>
<td width="10%"><button ng-click="addNewProduct(prod.id)" class="form-control">Add</button></td>
</tr>
</tbody>
</table>
<!--SECOND TABLE-->
<table ng-show="newProducts.length!=0" class="table">
<thead>
<tr>
<th >
Product Name
</th>
<th >
Qty
</th>
<th >
Price
</th>
<th >
Split
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="newProduct in newProducts">
<td width="60%" ng-bind="newProduct.uid"></td>
<td width="10%" ng-bind="newProduct.qty"></td>
<td width="10%"ng-bind="newProduct.price"></td>
<td width="10%" ng-bind="newProduct.split"></td>
<td width="10%"><button ng-show="newProducts.length!=0" ng-click="removeProduct(newProduct.uid)">X</button></td>
</tr>
</tbody>
</table>
Output
but whatever i type in the textbox of first table is coming just like that in second table. It is supposed to come list by list
In JS I am getting all details from input fields and settinf to an object prod and then pushing it in to an array newProducts.
Later in the table I am using ng-repeat to repeat items in newProducts array. The top table and bottom table are connected in no other way and I cannot figure out why values are chaging in bottom table when they are changed in input fields. Also while trying to add it one more time, it throws an error.
jquery.js:4409 Error: [ngRepeat:dupes] http://errors.angularjs.org/1.4.3/ngRepeat/dupes?p0=newProduct%20in%20newPr…0a-42d3-949e-3e8e59ac2be9%22%2C%22%24%24hashKey%22%3A%22object%3A359%22%7D
Here is the JS to add new item
//function to add new product while creating
$scope.addNewProduct= function(id){
$scope.newProducts.push($scope.prod);
console.log("product array-"+JSON.stringify( $scope.newProducts));
}
I tried console.log to log newProducts array in console, it is getting updated with new array , but not showing up in second table. Please help!
use angular copy.
angular $scopes are two way binded.. the changes u make in first table will be reflected in second table as you are pushing $scope.prod which is two way binded.
Using $scope can be very tricky. I'm not the best in Angular but i have no idea
$scope.newProducts.push($scope.prod);
if you are using here the $scope of the function or the $scope of the Controller.
Put in at the very top of your Controller "var vm=$scope", and in your html use "Controller as vm".
So if you are then there, we can see if the problem still exists.
Angular variables are reference type. So you can use angular.copy() to overcome from this issue. Below the code.
$scope.addNewProduct= function(id){
var products = angular.copy($scope.prod);
$scope.newProducts.push(products);
console.log("product array-"+JSON.stringify( $scope.newProducts));
}
Hope it will help you thanks.

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