To push selected values from one dynamic table to another dynamic table - angularjs

I have two tables named products and customers:-
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>Product Code</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in service track by $index" ng-class="{'ISselected': isSelected(row, $index)}" ng-click="selectedRow(row, $index)">
<td>{{row}}</td>
</tr>
</tbody>
</table>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>Customer Code</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in customers track by $index">
<td>{{row}}</td>
</tr>
</tbody>
</table>
And a button:-
<button type="button" class="btn btn-info">Add</button>
My directive code:-
scope.services = [];
scope.customers = [];
scope.selectedRowID = null;
scope.selectedRow = function(rowID){
scope.selectedRowID = scope.selectedRowID == rowID ? null : rowID;
}
scope.isSelected = function(rowID){
return (scope.selectedRowID == rowID);
}
What I want here is when I select a particular row/value from the 'products' table and press 'add' button then that row/value gets pushed or added to my customers' table. The data inside from both tables are coming from the backend.

You don't need a directive, rather controller functions will do the job by pushing the selected row into customer data.
Here is basic fiddler, which perform similar stuff. hope it helps.

What i understand is for every row you have ADD button so that you can transfer data from one table to another.
First add "ADD" button inside table for every row.
Then Add the ng-click directive to ADD button
<button type="button" class="btn btn-info" ng-click="transferData($index)">Add</button>
Then add this function to your Directive:
$scope.transferData=function(index){
$scope.customers.push($scope.services [index]);
};
This will meet your requirements.

Related

Second level sorting using smart table?

I have a paginated table using a smart table. I want to sort using first the status and then the code. I can't use orderBy from AngularJS because it will order the elements of each page, not all. And st-sort-default of smart table orders only for one column.
<table st-table="lista.displayedPublications" st-safe-src="lista.publications">
<thead>
<tr>
<th st-sort="publication.status" >STATO</th>
<th st-sort="publication.communicationCode">TREAT CD</th>
<th> ... </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="publication in lista.displayedPublications">
<td>{{publication.status}}</td>
<td>{{publication.communicationCode}}</td>
<td>...</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<div st-template="ListaTreatement/pagination.html" st-pagination="" st-items-by-page="10"></div>
</td>
</tr>
</tfoot>
</table>
In the controller:
public publications: PublicationExtended[];
public displayedPublications = [].concat(this.publications);
constructor(...){
new Api($http).getList(me.comunicationType, me.comunicationStatus).then(
function(response : angular.IHttpPromiseCallbackArg<PublicationExtended[]>) {
me.publications = response.data;
}
}
use $filter("orderBy")($scope.lista.displayedPublications, ["+status", "+code"]); in your controller to sort your data before providing it to your table. + and - can be used to set descending or ascending sort order.

Edit function not working after sort the data in angular js datatable

I have a table on html page and this table have 15 records. each column have sorting functionality.
There is a edit button on each row to edit row value in separate tab, its working fine before sorting of data.
Means if you have clicked on table's column than edit function is not called.
`<table id="tbl" class="table table-striped table-bordered"
datatable="ng" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Code</th>
<th>Status</th>
<th>Notes</th>
<th>Description</th>
<th style="text-align:center">Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="e in entities">
<td>{{e.name}}</td>
<td>{{e.code}}</td>
<td>{{getStatus(e.status)}}</td>
<td>{{e.notes}}</td>
<td>{{e.description}}</td>
<td align="center">
<span class="glyphicon glyphicon-pencil" />
<span style="color: #ddd;">|</span>
<span class="glyphicon glyphicon-trash" />
</td>
</tr>
</tbody>
</table>
And controller code as below :
$scope.edit = function (entity) {
alert('name');
$scope.entity = entity;
$scope.activate('view');
};
This function named as edit called until we not click on header of data table.
please suggests what is issue.. thanks in advance

Displaying dynamic views for multiple profiles (customers) with AngularJs

I am getting the data for customers and displaying in on table (ng-repeat) on the main page. The main page also has search option which filter the data by a particular customer ID.
<table id="searchResults" class="table table-bordered">
<tr>
<th>Klantnummer</th>
<th>Voorletters</th>
<th>Tussenvoegsel</th>
<th>Achternaam</th>
<th>Geboortdatum</th>
<th> Actief Sinds</th>
</tr>
<tr ng-repeat="data in allData | filter:kvk">
<td>{{data.kvk}}</td> //this is the customer ID
<td>{{data.voorletters}}</td>
<td>{{data.tussenvoegsel}}</td>
<td>{{data.achternaam}}</td>
<td>{{data.geboortedatum}}</td>
<td>{{data.actief}}</td>
</tr>
</table>
The result I want to reach is that when a user clicks on the customer ID (which is one of the rows on the table displayed), a new view should open, where more details about that particular customer can be seen. I know basics of routing, but I can not get the best way to solve this problem, as there are many customers!
How can I give each customer ID, a different view that shows detail of that customer? What tools does Angular have for that? Just need a rough idea how to approach this problem using AngularJS!
Well you could either redirect user to a 'show' page like so:
<table id="searchResults" class="table table-bordered">
<tr>
<th>Klantnummer</th>
<th>Voorletters</th>
<th>Tussenvoegsel</th>
<th>Achternaam</th>
<th>Geboortdatum</th>
<th> Actief Sinds</th>
<th></th>
</tr>
<tr ng-repeat="data in allData | filter:kvk">
<td>{{data.kvk}}</td> //this is the customer ID
<td>{{data.voorletters}}</td>
<td>{{data.tussenvoegsel}}</td>
<td>{{data.achternaam}}</td>
<td>{{data.geboortedatum}}</td>
<td>{{data.actief}}</td>
<td><a ng-click="viewCustomer(data.kvk)" class="btn btn-xs btn-success"><span class="glyphicon glyphicon-search"></span></a></td>
</tr>
</table>
then in your controller:
$scope.viewClient = function(id) {
//path to your view using id
};
or else create a hidden table in the same view and show upon button click. I am using bootstrap accordion for sample purposes.
<table id="searchResults" class="table table-bordered">
<tr>
<th>Klantnummer</th>
<th>Voorletters</th>
<th>Tussenvoegsel</th>
<th>Achternaam</th>
<th>Geboortdatum</th>
<th> Actief Sinds</th>
<th></th>
</tr>
<tr ng-repeat="data in allData | filter:kvk">
<td>{{data.kvk}}</td> //this is the customer ID
<td>{{data.voorletters}}</td>
<td>{{data.tussenvoegsel}}</td>
<td>{{data.achternaam}}</td>
<td>{{data.geboortedatum}}</td>
<td>{{data.actief}}</td>
<td><a data-toggle="collapse" data-target="#{{data.kvk}}"></a> </td>
</tr>
<tr>
<td>
<div class="accordion-body collapse" id="{{data.kvk}}">
<!-- your content here -->
</div>
</td>
</table>
hope it helps.

angularjs pagination using smart table

By using angular smart table, how do i get the result set by using offset value.
For example, I have 100 records in the database
First i need to get 20 records from database and to display only 10 items per page.
After clicking the 3rd page, need to query the database(service call) and get the another 20 records..etc(but no server call for 2nd page)
I am using smart table pipe/ajax plugin to display the records.
How to achieve using this.
<div class="table-container" ng-controller="pipeCtrl as mc">
<table class="table" st-pipe="mc.callServer" st-table="mc.displayed">
<thead>
<tr>
<th st-sort="id">id</th>
<th st-sort-default="reverse" st-sort="name">name</th>
<th st-sort="age">age</th>
<th st-sort="saved">saved people</th>
</tr>
<tr>
<th><input st-search="id"/></th>
<th><input st-search="name"/></th>
<th><input st-search="age"/></th>
<th><input st-search="saved"/></th>
</tr>
</thead>
<tbody ng-show="!mc.isLoading">
<tr ng-repeat="row in mc.displayed">
<td>{{row.id}}</td>
<td>{{row.name}}</td>
<td>{{row.age}}</td>
<td>{{row.saved}}</td>
</tr>
</tbody>
<tbody ng-show="mc.isLoading">
<tr>
<td colspan="4" class="text-center"><div class="loading-indicator"></div>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td class="text-center" st-pagination="" st-items-by-page="5" colspan="4">
</td>
</tr>
</tfoot>
</table>
</div>
http://lorenzofox3.github.io/smart-table-website/
code in the Plunker
http://plnkr.co/edit/wzUHcc9PBF6tzH8iAEsn?p=preview
You need to add st-safe-src="tablecollection" as well as st-table=tablerow
Then,
<tr ng-repeat="row in tablerow">
FMI,
source: Client side pagination not working in smart table
Set the page size to 10.
Maintain a service level array object (var fetchedData) for the fetched rows from the server.
Only call the server if the required amount of data not available in the client side.
Always filter the data for the pagination from fetchedData.
Something like this in your service.
var fetchedData = [];
function getPage(start, number, params) {
if (fetchedData.length < (start + number)) {
//get the next 20 rows from the server and add to fetchedData;
}
var filtered = params.search.predicateObject ?
$filter('filter')(fetchedData, params.search.predicateObject) :
fetchedData;
//rest of the logic

How to get row data from table using angularjs

I am new to angularjs. I am facing an issue. I have a table with one radio button. When the user selects any radio button and click on the submit button, I need to show the selected rows details.
Html code:
<table>
<thead>
<tr>
<th>Select</th>
<th>First Name</th>
<th>Last Name</th>
<th>Unique Reference ID</th>
<th>Country</th>
<th>Branch</th>
<th>Card No</th>
</tr>
</thead>
<tr ng-repeat="d in Employees">
<td><input type="radio"></td>
<td>{{d.fname}}</td>
<td>{{d.lname}}</td>
<td>{{d.uniqueid}}</td>
<td>{{d.country.name}}</td>
<td> {{d.branch.name}}</td>
<td>{{d.cardno}}</td>
</tr>
</table>
<table>
<tr>
<td><input type="button" value="Edit" ng-click="Edit()"></td>
</tr>
</table>
controller code:
$scope.Edit=function()
{
//need id of selected row ?
};
Something like this:
<input type="radio" ng-click="editData.employee = d">
And the controller:
$scope.editData = {};
$scope.Edit = function() {
var id = $scope.editData.employee.id;
};
I just answered another question about how it affects your code that ng-repeat creates a new scope for each list item, which is why you need the editData object for it to work. It could help you understand why you need it: Angular replace data from ng-repeat item
You'll want to use ng-model and ng-value attributes in your radio input; see http://docs.angularjs.org/api/ng/input/input%5Bradio%5D.
You'll also want to format your html with at least some semblance of sanity.

Resources