I am using onaftersave() function to save the table data. In dir-paginate i am using ng-repeat to read the table row values. I kept itemsperpage is 5. obviously 6th row will be display in second Page. When I try to edit the second page row values it is not updating the second page rows. How to resolve it?
<form editable-form name="tableform1" oncancel="cancel()" onaftersave="saveTable(Manage_Role.Description)">
<div class="row">
<div class="col-xs-12">
<div class="panel panel-default panel-table">
<div class="panel-heading">
<div class="row">
<div class="col col-xs-6">
</div>
<div class="col col-xs-6 text-right">
<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-sm btn-primary btn-create" title="Add New Role">Add New Role</button>
</div>
</div>
</div>
<div class="panel-body scrollbar">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th style="width: 25%" align="center">
Name
</th>
<th style="width: 35%">
Description
</th>
<th style="width: 30% " align="center">
IsActive?
</th>
<th style="width: 10% " align="center"><a href="" ng-click="orderByField='IsActive';
reverseSort = !reverseSort" title="Assign">Assign</a></th>
<th style="width: 1%" align="center" ng-show="false">DirtyFlag</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" id="RoleNameID" ng-model="Manage_Role1.RoleName" placeholder="search" class="searchbox" onkeydown="return (event.keyCode!=13);"
/>
</td>
<td>
<input type="text" id="DescriptionID" ng-model="Manage_Role1.Description" placeholder="search" class="searchbox" onkeydown="return (event.keyCode!=13);"
/>
</td>
<td>
<select name="DropFilter" ng-model="Manage_Role1.IsActive" class="searchbox">
<option value="">All</option>
<option value=false>False</option>
<option value=true>True</option>
</select>
</td>
<!--<td></td>-->
</tr>
<tr dir-paginate="Manage_Role in Manage_Roleser | itemsPerPage:5 | filter:DropFilter | filter:Manage_Role1 | orderBy:orderByField:reverseSort "
ng-class-odd="'odd'">
<td ng-click="tableform1.$show()">
<span e-ng-change="applyHighlight($data,$index)" editable-text="Manage_Role.RoleName" ng-attr-title="{{Manage_Role.RoleName}}"
e-form="rowform" ng-click="rowform.$show()">
{{ Manage_Role.RoleName | uppercase }}
</span>
</td>
<td ng-click="tableform1.$show()">
<div>
<span e-ng-change="applyHighlight($data,$index)" editable-text="Manage_Role.Description" e-form="rowform" ng-attr-title="{{Manage_Role.Description}}"
ng-click="rowform.$show()">
{{ Manage_Role.Description || 'empty' }}
</span>
</div>
</td>
<td ng-click="tableform1.$show()" align="center">
<span e-ng-change="applyHighlight($data,$index)" ng-checked="Manage_Role.IsActive" editable-checkbox="Manage_Role.IsActive"
e-form="rowform" ng-click="applyHighlight($data,$index);tableform.$show()">
<input type="checkbox" ng-model="Manage_Role.IsActive" width="20" ng-attr-title="{{Manage_Role.IsActive}}" />
</span>
</td>
<td align="center">
<input type="image" data-toggle="modal" ng-click="Rolepopupclick(Manage_Role._id,Manage_Role.RoleName)" title="Assign UI"
data-target="#Div1" src="App_Themes/Images/AssignUser.png"
alt="Submit" width="28" height="28" />
</td>
<td ng-show="false">
<input type="text" ng-model="Manage_Role.DirtyFlag" ng-show="false" />
</td>
</tr>
</tbody>
</div>
</table>
</div>
<div class="panel-footer">
<div class="row">
<div class="col col-xs-8">
<dir-pagination-controls max-size="5" direction-links="true" boundary-links="true">
</dir-pagination-controls>
</div>
<div class="col col-xs-4">
<div class="btn-form" ng-show="tableform1.$visible" style="float:right">
<button type="submit" ng-disabled="tableform1.$waiting" title=" Save Changes" class="btn btn-primary fa fa-save" ng-click="NotifyClick()"> Save</button>
<input type="button" ng-disabled="tableform1.$waiting" title=" Close Edit Form Without Saving Changes" ng-click="refreshUI();tableform1.$cancel()"
class="btn btn-danger fa fa-close" value="X Cancel" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
controller code:
$scope.saveTable = function ()
{
debugger;
if(NotifyCount!=1){
var RoleNamechk = '';
for (var i = 0; i < $scope.Manage_Roleser.length; i++) {
RoleNamechk = $scope.Manage_Roleser[i].RoleName;
for (var j = 0; j < $scope.Manage_Roleser.length; j++) {
var RoleName = $scope.Manage_Roleser[j].RoleName;
if (RoleNamechk == RoleName) {
count++;
}
}
}
if (count == $scope.Manage_Roleser.length)
{
for (var i = 0; i < $scope.Manage_Roleser.length; i++) {
var id = $scope.Manage_Roleser[i]._id;
var rolename = $scope.Manage_Roleser[i].RoleName;
var isactive = $scope.Manage_Roleser[i].IsActive;
var description = $scope.Manage_Roleser[i].Description;
if (description == "")
{
description = 'empty';
}
if ($scope.Manage_Roleser[i].DirtyFlag == "True")
{
$scope.LoggedinUsers = $cookieStore.get('LoggedinUser');
var updatedBy= $scope.LoggedinUsers;
$http.put('/Roleupdate/' + id + '/' + rolename + '/' + isactive + '/' + description + '/' + updatedBy).then(function (response) {
refresh();
});
}
count=0;
}
$notify.success('Success', 'Role is Updated Successfully');
}
else {
$notify.warning('Warning', 'Role Name is Already Exists');
count = 0;
return '';
}
}
};
in ng-change I am checking dirty flag of selected index because it is updating all the row values. for that I am updating only selected($dirty) row alone. In second page it is not taking table index correctly. If I select 2nd page 3 row it will assume or taking index of the particular page. It should take index of selected row from the over all table row
$scope.applyHighlight = function ($data,index) {
$scope.Manage_Roleser[index].DirtyFlag = "True";
var dataSpan = $(event.currentTarget).closest('td');
if (!dataSpan.hasClass("highlighted")) {
$(dataSpan).addClass("highlighted");
}
}
Related
My code is like this: when you check the 'hide' column, the whole row is hidden. I also have a 'Show All' checkbox. When I check it, all rows (including the hidden ones) are shown. But when I uncheck it, all rows disappear. How can I make it so only the hidden rows disappear when I uncheck 'Show All', and the other rows still remain visible?
<body ng-app="myApp" ng-controller="myController">
<h1>Fruits in Vietnam</h1>
<hr>
<form name="myForm">
<div class="input-group input-group-lg">
<input type="text" class="form-control" name="mdfruitname" id="txtfruitname" ng-model="mdfruitname"
required>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" ng-click="addnew()"
ng-disabled="myForm.mdfruitname.$pristine || myForm.mdfruitname.$invalid">Add
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Hide</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="fruit in fruitnameDetail" ng-show="showall" ng-hide="hidef">
<td>{{fruit.fruitname}}</td>
<td><input type="checkbox" ng-model="hidef"></td>
<td>
<a class="btn btn-xs delete-record" ng-click="removefruitname($index)">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div><input type="checkbox" ng-model="showall"><span>SHOW ALL</span></div>
</body>
<script>
var app = angular.module("myApp", []);
app.controller('myController', function ($scope, $window) {
$scope.fruitnameDetail = [
{
"fruitname": "Banana"
},
{
"fruitname": "Mango"
},
{
"fruitname": "Orange"
}
];
$scope.addnew = function () {
var fruitnameDetail = {
fruitname: $scope.mdfruitname
};
$scope.fruitnameDetail.push(fruitnameDetail);
$scope.mdfruitname = '';
};
$scope.removefruitname = function (index) {
var name = $scope.fruitnameDetail[index].fruitname;
if ($window.confirm("Do you want to delete " + name + " ?")) {
$scope.fruitnameDetail.splice(index, 1);
}
};
});
</script>
Do not use ng-show and ng-hide at the same time. Just change a little bit your condition for ng-repeat. Here the example that should work:
<body ng-app="myApp" ng-controller="myController">
<h1>Fruits in Vietnam</h1>
<hr>
<form name="myForm">
<div class="input-group input-group-lg">
<input type="text" class="form-control" name="mdfruitname" id="txtfruitname" ng-model="mdfruitname"
required>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" ng-click="addnew()"
ng-disabled="myForm.mdfruitname.$pristine || myForm.mdfruitname.$invalid">Add
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Hide</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="fruit in fruitnameDetail" ng-show="showall || !hidef">
<td>{{fruit.fruitname}}</td>
<td><input type="checkbox" ng-model="hidef"></td>
<td>
<a class="btn btn-xs delete-record" ng-click="removefruitname($index)">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div><input type="checkbox" ng-model="showall"><span>SHOW ALL</span></div>
</body>
i'm trying to pipe the values of my table to show only the things i want, actually with "EMPRESAS", "TIPO USUARIO"; it's working(with some errors but i will study on my own to fix that). But with status i get the return of how many "ATIVOS", and "INATIVOS" i got, but when i trying to list him in the table, in my ATIVOS appear the INATIVO, how to fix that? i thing its something happening because inATIVOS and ATIVOS had commun chars, btw i don't know how to fix that
<div class="row">
<div class="col-md-12">
<app-card cardTitle="Informe os parâmetros da pesquisa">
<form (ngSubmit)="onSubmit(selectVal.value, selectedOption)">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class=" form-label"
style="font-weight: bold;"
>Filtrar pesquisa</label>
<select class="form-control" #selectVal name="filterOption" formControlName="filterOption">
<option value="TODOS">TODOS</option>
<option value="empresa">EMPRESAS</option>
<option value="tipo_usuario">TIPO DO USUÁRIO</option>
<option value="status">STATUS DO USUÁRIO</option>
</select>
</div>
</div>
<div
*ngIf="selectVal.value == 'empresa'"
class="var-select" class="col-md-2">
<div class="form-group">
<div >
<label class="form-label"
style="font-weight: bold">Empresa</label>
<select class="form-control" name="empresa" [(ngModel)]="selectedOption" >
<option *ngFor="let usuario of usuarios | pEmpresa : selectedOption" value={{usuario.empresa}}> {{usuario.empresa}}</option>
</select>
</div>
</div>
</div>
<div
*ngIf="selectVal.value == 'tipo_usuario'"
class="var-select" class="col-md-2">
<div class="form-group">
<div>
<label class="form-label" style="font-weight: bold">Tipos do usuário</label>
<select class="form-control" name="tipo_usuario" [(ngModel)]="selectedOption">
<option *ngFor="let usuario of usuarios | pTipo : selectedOption " value={{usuario.tipo_usuario}}>{{usuario.tipo_usuario}} </option>
</select>
</div>
</div>
</div>
<div
*ngIf="selectVal.value == 'status'"
class="var-select" class="col-md-2">
<div class="form-group">
<div >
<label class="form-label" style="font-weight: bold">Status dos usuários</label>
<select class="form-control" name="status" [(ngModel)]="selectedOption">
<option *ngFor="let usuario of usuarios | pStatus : selectedOption" value={{usuario.status}}>{{usuario.status}}</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<div class="col-md-12">
<button type="submit" class="btn btn-warning pos">CONSULTAR</button>
</div>
</div>
</div>
</form>
</app-card>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" class="btn btn-success" (click)="cadastrarNovoUsuario()">Cadastrar Usuario</button>
</div>
</div>
<br>
<div class="row">
<div class="col-md-12" *ngIf="carregar_lista_usuarios">
<app-card cardTitle="Usuários" cardClass="card-datatable" [options]="false">
<div class="table-responsive col-md-12">
<table datatable [dtOptions]="dtResponsiveOptions" class="table table-striped table-bordered table-hover" >
<thead>
<tr>
<th style="visibility: hidden; width: 1%; border-collapse: inherit; border-color: transparent;"></th>
<th>NOME</th>
<!-- <th>UID</th> -->
<th>EMPRESA</th>
<th>E-MAIL</th>
<th>TELEFONE</th>
<th>STATUS</th>
<th>AÇÃO</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let usuario of usuarios | filter : selectedOption">
<div class="imagem text vasco" style="border-radius: 80%; height: 60px; border-color: transparent;" ><img
[src]="usuario.imagem_url == '' || usuario.imagem_url == 'null' ? asset : usuario.imagem_url" class="img-radius align-center" style="width:45px"></div>
<td class="text" style="width: 5%; max-width: 4.8rem;">{{usuario.nome_usuario}}</td>
<!-- <td style="width: 1%;">{{usuario.uid}}</td> -->
<td class="text" style="width: 11%; max-width: 5.7rem">{{usuario.empresa}}</td>
<td class="text" style="width: 10%; max-width: 10.9rem">{{usuario.email}}</td>
<td mask="(00)0 0000 0000" class="text" style="width: 10%; max-width: 4rem">{{usuario.celular}}</td>
<td class="text" style="width: 10%; max-width: 3rem">{{usuario.status}}</td>
<td class="text" style="width: 10%;">
<button type="submit" class="btn btn-success" (click)="editarUsuario(usuario.uid)"><i class="feather icon-edit"></i></button>
<button *ngIf="adm_op" type="submit" class="btn btn-danger" (click)="apagarUsuario(usuario.uid)"><i class="feather icon-x-circle"></i></button></td>
</tr>
</tbody>
</table>
</div>
</app-card>
</div>
</div>
This is the PIPE i'm using in the HTML
Pipe.TS
#Pipe({name: "pStatus"})
export class PipeStatus implements PipeTransform {
transform(usuarios: Array<Usuario>, selectedOption){
let result = []
let obj = {}
let obj2 = 'status'
console.log("SELECIONADO: " , selectedOption)
usuarios.forEach((item, i) => {
obj[item[obj2]] = i;
console.log("value", item.status)
});
for(let key in obj){
let idx = obj[key]
console.log("IDX", idx, "OBJ for", obj, 'KEY', key)
result.push(usuarios[idx])
}
return result
```
I have MySQL database used with Codigniter including following table too.
+-------------------+-----------------+------+-------+--------+
| update_request_id | update_stock_id | item | r_qty | status |
+-------------------+-----------------+------+-------+--------+
And used the following for loop in Controller, to update records in the table.
$count = count($this->input->post('item_id'));
$items = $this->input->post('item_id');
$qts = $this->input->post('qty');
for ($x = 0; $x < $count; $x++) {
$udetails[$x]['update_stock_id'] = $id;
$udetails[$x]['item'] = $items[$x];
$udetails[$x]['r_qty'] = $qts[$x];
$udetails[$x]['status'] = 1;
}
And the following View used to get relevant values for the controller.
<?php
if(!empty($itemReqFromHD)){
$newMaster=$itemReqFromHD[0];
}
?>
<script type="text/javascript">
$(document).on("change", "#item", function () {
$.ajax({
'url': '<?=site_url("item/isExistProduct/?q=")?>' + $('#item').val(),
'method': 'GET',
'success': function (data) {
//console.log(data);
var jData = JSON.parse(data);
if (jData.status == true) {
$('#request_table').append('<tr>' +
'<td ><span id="product" >' + jData.data[0].item_name + '</span>' +
'<input type="hidden" id="item_id[]" name="item_id[]" value="'+jData.data[0].item_id+'">' +
'</td>' +
'<td class="text-center"><input class="form-control" autofocus required type="number" step="any" id="qty['+jData.data[0].item_id+']" name="qty['+jData.data[0].item_id+']" ></td>' +
'<td class="text-center" ><i class="fa fa-remove remove" style="cursor: pointer"></i></td>' +
'</tr>');
}
},
'error': function () {
}
});
});
$(document).on("click", ".remove", function () {
$(this).closest('tr').remove();
});
</script>
<div class="box box-info">
<div class="box box-info collapsed-box">
<div class="box-header with-border">
<h3 class="box-title">Update Item Request From HD</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" style="font-size: 16px;" data-widget="collapse"><i
class="fa fa-plus"></i>
</button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body" style="display: block">
<form action="<?= site_url('item/editItemReqFromHD/'.$newMaster->update_stock_id) ?>" method="post">
<div class="row">
<div class="col-md-3">
<div class="form-group"><label>Request Date</label>
<input type="date" name="request_date" id="request_date" class="form-control" value="<?=$newMaster->billed_date?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group"><label>Select Product</label>
<select name="item" id="item" class="form-control select2" >
<option value="">Select Product</option>
<?php
if (!empty($products)) {
foreach ($products as $row) {
?>
<option value="<?= $row->item_id ?>"><?= $row->item_name ?></option>
<?php
}
}
?>
</select>
</div>
</div>
</div>
<!--table-->
<div class="col-md-12 column">
<div class="col-md-12">
<div class="control-group table-group">
<label class="table-label">Request Items *</label>
<div class="controls table-controls">
<table id="request_table"
class="table items table-striped table-bordered table-condensed table-hover">
<thead>
<tr style="background-color: #3c8dbc">
<th class="col-md-8">Product Name</th>
<th class="text-center" class="col-md-2">Quantity</th>
</th>
<th style="width: 30px !important; text-align: center;">
<i class="fa fa-trash-o" style="opacity:0.5; filter:alpha(opacity=50);"></i>
</th>
</tr>
</thead>
<tbody>
<?php
foreach ($itemReqFromHD as $row){
?>
<tr>
<td ><?=$row->item_name?>
<input type="hidden" id="item_id[]" name="item_id[]" value="<?=$row->item_id?>">
</td>
<td class="text-center"><input class="form-control" value="<?=$row->r_qty?>" required type="number" step="any" id="r_qty[<?=$row->item_id?>]" name="r_qty[<?=$row->item_id?>]" ></td>
<td class="text-center"><i class="fa fa-remove remove" style="cursor: pointer"></i></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-primary btn-block">Update Request</button>
</div>
</div>
</form>
</div>
</div>
</div>
All codes are working fine but at the time of the update the column 'r_qty' is not edited, leaving the table as follows:
Array
(
[0] => Array
(
[update_stock_id] => 577
[item] => 2
[r_qty] =>
[status] => 1
)
[1] => Array
(
[update_stock_id] => 577
[item] => 4
[r_qty] =>
[status] => 1
)
)
I could not catch what I am going wrong ? Can anyone help me ?
I am writing a small program in Vue.js, but I am getting stuck with an error.
I want the X button to remove each item in a list. I used splice(index,1), but the item isn't being removed. What am I missing?
My HTML:
<div id="app" class="container">
<div class="row">
<div class="col-md-4">
<h1>Add Student</h1>
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" v-model="newStudent.name" class = "form-control" placeholder="Student Name">
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" id="address" v-model="newStudent.address" class = "form-control" placeholder="Address">
</div>
<button class="btn btn-success" v-on:click = "addStudent">Add</button>
</div>
<div class="col-md-8">
<h1>All Students</h1>
<table class="table table-striped">
<thead>
<tr>
<td>Name</td>
<td>Address</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr v-for = "student in students">
<td>{{student.name}}</td>
<td>{{student.address}}</td>
<td><button type="button" class="btn btn-danger" v-on:click="deleteStudent($index)">X</button></td>
</tr>
</tbody>
</table>
</div>
</div> <!--End of Row-->
<br>
<br>
<div class="row">
<div class="col-md-12">
<pre>{{ $data | json }}</pre>
</div>
</div>
</div>
My JS:
<script>
new Vue({
el: "#app",
data: {
newStudent: {name: "", address: ""},
students: []
},
methods: {
addStudent: function(){
var name = this.newStudent.name.trim();
var address = this.newStudent.address.trim();
if(name && address){
this.students.push({name: name, address: address});
this.newStudent = {name: "", address: ""};
$("#name").focus();
}
},
deleteStudent: function(index){
this.students.splice(index,1)
}
}
});
</script>
The $index variable was removed in Vue 2. So, you're not passing the index in correctly.
Specify the index variable in the v-for and pass that to the deleteStudent method instead:
<tr v-for="student, index in students">
<td>{{student.name}}</td>
<td>{{student.address}}</td>
<td>
<button
type="button"
class="btn btn-danger"
v-on:click="deleteStudent(index)"
>X</button>
</td>
</tr>
This is covered in the documentation on list rendering in Vue.
When i start typing a name of student, like "M", the list of student needs to include only students, name of that are starting on letter "M" and so on rest of the word. But input value .length is undefined all the time.
(function() {
var app = angular.module('app', []);
app.controller('DataController', function() {
this.students = arr;
this.compare = function() {
for (var i = 0; i < this.text.length; i++) {
if (this.text[i] == this.students.name[i]) {
alert(this.text);
return true;
}
}
}
});
var arr= [{
name: 'Azurite',
price: 2.95
}, {
name: 'Bloodstone',
price: 5.95
}, {
name: 'Zircon',
price: 3.95
}];
}());
HTML
<div class="container-fluid">
<div class="row-fluid">
<input class="col-md-12 col-xs-12" type="text" placeholder="Search people by name..." ng-model='text' ng-change='data.students.name'>
<div class="buttons">
<button class="btn btn-sort">Sort by name</button>
<button class="btn btn-sort">Sort by age</button>
<button ng-click='data.click()' class="btn btn-danger">Reset</button>
</div>
</div>
<!--Main content-->
<div class="main-table col-sm-8 col-md-7 col-md-offset-1 col-lg-7 col-lg-offset-1">
<table class="table table-hover">
<thead>
<tr>
<th class="text-center">Image</th>
<th>Name</th>
<th>Age</th>
<th>Phone</th>
</tr>
</thead>
<tbody ng-repeat='student in data.students' ng-show='data.compare()'>
<tr>
<td>
<img src="/img/cat.svg" alt="">
</td>
<td>{{student.name}}</td>
<td>41</td>
<td>sieg#example.com</td>
</tr>
</tbody>
</table>
</div>
</div>
The angular way to do this is to use the filter feature built in to angular.
first, the text box you want to type your search into:
<input class="col-md-12 col-xs-12" type="text"
placeholder="Search people by name..." ng-model='data.text'>
Note that this only needs an ng-model value.
Next, the ng-repeat:
<tbody ng-repeat='student in data.students | filter:data.text'>
Nothing is necessary at all in the controller.
http://plnkr.co/edit/aoR2ZkrgjCvhC60Ky0QA?p=preview