How to enable only parent table raw items as editable? - angularjs

When click on edit button (ng-click="editmode = !editmode") the entire table input showing. is there any solution to show that only show its <input type="text"> as editable ?
var app = angular.module('myapp', []);
app.controller('testController', function($scope) {
$scope.userdetails = {
"id": "1",
"user_id": "2",
"name": "Alycia",
"address": "510 Marks Parkway Suite 221\nLake Karelle, SC 01791",
"post": "Howellmouth",
"district": "Schaeferside",
"state": "New Mexico",
"pin": "61354-9529",
"phone": "(239)009-2861x858",
"mobile1": "+70(1)8058651903",
"mobile2": "+69(3)0049980344",
"file_id": "1",
"email1": "Diana11#Sipes.info",
"email2": "Dietrich.Georgianna#hotmail.com",
"created_at": "2015-08-04 11:41:56",
"updated_at": "2015-08-04 11:41:56"
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div ng-app="myapp" ng-controller="testController" class="container">
<table class="table table-hover table-responsive">
<tbody>
<tr>
<th>Name</th>
<td ng-if="!editmode">{{userdetails.name}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.name">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Address</th>
<td ng-if="!editmode">{{userdetails.address}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.address">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Post</th>
<td ng-if="!editmode">{{userdetails.post}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.post">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>District</th>
<td ng-if="!editmode">{{userdetails.district}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.district">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>State</th>
<td ng-if="!editmode">{{userdetails.state}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.state">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Pin</th>
<td ng-if="!editmode">{{userdetails.pin}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.pin">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Phone</th>
<td ng-if="!editmode">{{userdetails.phone}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.phone">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Mobile 1</th>
<td ng-if="!editmode">{{userdetails.mobile1}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.mobile1">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Mobile 2</th>
<td ng-if="!editmode">{{userdetails.mobile2}}</td>
<td ng-if="editmode">
<input type="text" ng-model="userdetails.mobile2">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editmode = !editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>

You should just give a different name on each part instead of "editmode" on every input :
<tr>
<th>Name</th>
<td ng-if="!editName">{{userdetails.name}}</td>
<td ng-if="editName">
<input type="text" ng-model="userdetails.name">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editName = !editName"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
<tr>
<th>Address</th>
<td ng-if="!editAdress">{{userdetails.address}}</td>
<td ng-if="editAdress">
<input type="text" ng-model="userdetails.address">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="editAdress = !editAdress"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
Hope it helped.
EDIT :
Here is an other proposition working in this plunker
If you manage a bit your $scope data you can have a lot less HTML to produce
The data would look like this :
$scope.userdetails = {
"id": {
value : "1",
label: "ID"
},
"user_id": {
value : "2",
label: "User Id"
},
"name": {
value : "Alycia",
label: "Name",
display: true
},
"address": {
value : "510 Marks Parkway Suite 221\nLake Karelle, SC 01791",
label: "Address",
display: true
},
"post": {
value : "Howellmouth",
label: "Post",
display: true
}
};
And the HTML Like this :
<table class="table table-hover table-responsive">
<tbody>
<tr ng-if="property.display" ng-repeat="property in userdetails">
<th>{{property.label}}</th>
<td ng-if="!property.editmode">{{property.value}}</td>
<td ng-if="property.editmode">
<input type="text" ng-model="property.value">
</td>
<td>
<button class="btn btn-default btn-xs" ng-click="property.editmode = !property.editmode"><span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
</tr>
</table>

Related

How do I get all results where at least one property contains the parameter passed in the filter? (angullarjs)

I am trying to convert my paginated table from individual columns to a search all columns that contain the result.
//Newly added input that I want to query all columns
<input type="text" ng-model="searchCriteria" />
<table ng-table="tableParams" class="table table-condensed" show-filter="true">
<tr ng-repeat="memberInfo in $data">
<td data-title="'Name'" filter="{ Name: 'text'}" sortable="'Name'">
{{memberInfo.Name}}
</td>
<td data-title="'Location'" filter="{ Location: 'text'}" sortable="'Location'" style="width: 275px;">
{{memberInfo.Location}}, {{memberInfo.country}}
</td>
<td data-title="'Phone'" >
{{memberInfo.Phone}}
</td>
<td data-title="''" style="width: 30px;">
<button type="button" class="btn btn-xs btn-info" title="View on map" ng-click="goToMarker(memberInfo.Key)">Map</button>
</td>
</tr>
</table>
Above you can see I have each column has it's own filter, but I want to remove them and have a single catch all.
I have added a screen shot below of a visual mockup
Thank you.
UPDATE
I got the filters to work, but not with the pagination...
<input type="text" class="form-control" placeholder="Search name, phone, or location" ng-model="queryFilter" />
<table ng-table="tableParams" class="table table-condensed" show-filter="true">
<tr ng-repeat="memberInfo in $data | filter:query">
<td data-title="'Name'" sortable="'Name'">
{{memberInfo.Name}}
</td>
<td data-title="'Location'" sortable="'Location'" style="width: 275px;">
{{memberInfo.Location}}, {{memberInfo.country}}
</td>
<td data-title="'Phone'" >
{{memberInfo.Phone}}
</td>
<td data-title="''" style="width: 30px;">
<button type="button" class="btn btn-xs btn-info" title="View on map" ng-click="goToMarker(memberInfo.Key)">Map</button>
</td>
</tr>
</table>
And in the controller I have added this method
$scope.query = function (memberInfo) {
return memberInfo.Name.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
|| memberInfo.Location.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
|| memberInfo.Phone.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
|| memberInfo.Country.toLowerCase().indexOf($scope.queryFilter.toLowerCase()) !== -1
;
};

Can not show a default value in ng-select

I have following code. I want to show a value in select from infoData--> selection field, but failed.
<tbody>
<tr ng-repeat="emp in infoData">
<td>
<input name="selection{{$index}}" ng-model="emp.name" ng-disabled="!enabledEdit[{{$index}}]" />
</td>
<td>
<select name="name{{$index}}" ng-model="emp.selection" ng-options="employe.id as employe.name for employe in designationList" ng-disabled="!enabledEdit[{{$index}}]"></select>
</td>
<td>
<input name="email{{$index}}" ng-model="emp.email" ng-disabled="!enabledEdit[{{$index}}]"/>
</td>
<td >
<div class="buttons" align="center">
<button class="btn btn-sm btn-primary" ng-click="editEmployee($index)">Edit</button>
<!--<button class="btn btn-sm btn-danger" ng-click="deleteEmployee($index)">Delete</button>-->
</div>
</td>
</tr>
</tbody>
How to select selection value in infoData in select ?
$scope.infoData = [
{ name: $scope.applicant, selection: "Debtor", email:"a#gmail.com"},
{ name: $scope.secureParty, selection:"Secured Party", email:"b#gmail.com"}
];
and
$scope.designationList = [
{name:"Debtor", id:"1"},
{name:"Secured Party", id:"2"}
];
Here I want to see a selected value in select

I am assigning the dynamic id to the different element in HTML, but the id's are not working properly

<table ng-show = "noTaskAdded != 1" class="table table-hover hd-bg table-bordered">
<thead align="center">
<tr>
<th>SI No</th>
<th>Assigned Task</th>
<th>Closure Date</th>
<th>Comments</th>
<th>Status</th>
<th>Delete</th>
<th>Edit<th>
<td width = "20%">
<input class="form-control" ng-disabled = "x.status_flag == 1" id="{{ 'datepicker' + ($index + 8 ) }}" >
</td>
</thead>
<tbody ng-repeat="x in viewParticipantsComments">
<td>{{$index + 1}}</td>
<td width = "30%">
<textarea class="form-control" rows="3" cols="30" id = "description" ng-disabled = "x.status_flag == 1" ng-model = "x.task_description"></textarea>
</td>
<td width = "20%">
<input class="form-control" ng-disabled = "x.status_flag == 1" id="{{ 'datepicker' + ($index + 8 ) }}" >
</td>
<td ng-show = "x.status_flag == 1" width = "30%">
<textarea class="form-control" rows="3" cols="30" id = "description" ng-disabled = true>{{x.comments}}</textarea>
</td>
<td ng-show = "x.status_flag == 0">NA</td>
<td ng-show = "x.status_flag == 0">
<button class="btn btn-warning btn-sm waves-effect waves-light" alt="default">Pending</button>
</td>
<td ng-show = "x.status_flag == 1"> <button class="btn btn-success btn-sm waves-effect waves-light" alt="default">Done</button></td>
<td>
<button class="btn btn-danger btn-sm waves-effect waves-light" alt="default" ng-disabled = "x.status_flag == 1" ng-click = "deleteEditParticipants(x.id,x.task_description,x.closure_date,'delete')">Delete</button>
</td>
<td>
<button class="btn btn-primary btn-sm waves-effect waves-light" alt="default" ng-disabled = "x.status_flag == 1" ng-click = "deleteEditParticipants(x.id,x.task_description,x.closure_date,'update')">Update</button>
</td>
</tbody>
</table>
Here, i am using ng-repeat to assign the dynamic id's to the different element, and i have defined the datepickers of same name of id's like datepicker8, datepicker9 etc. But they are not getting called means they are not opening on click of that elements.
You need to fix your HTML because this is invalid and your browser will not be able to handle it properly:
<table ng-show = "noTaskAdded != 1" class="table table-hover hd-bg table-bordered">
<thead align="center">
<tr>
<th>SI No</th>
<th>Assigned Task</th>
<th>Closure Date</th>
<th>Comments</th>
<th>Status</th>
<th>Delete</th>
<th>Edit<th>
<th width = "20%">
<input class="form-control" ng-disabled = "x.status_flag == 1" id="{{ 'datepicker' + ($index + 8 ) }}" >
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in viewParticipantsComments">
<td>{{$index + 1}}</td>
<td width = "30%">
<textarea class="form-control" rows="3" cols="30" id = "description" ng-disabled = "x.status_flag == 1" ng-model = "x.task_description"></textarea>
</td>
<td width = "20%">
<input class="form-control" ng-disabled = "x.status_flag == 1" id="{{ 'datepicker' + ($index + 8 ) }}" >
</td>
<td ng-show = "x.status_flag == 1" width = "30%">
<textarea class="form-control" rows="3" cols="30" id = "description" ng-disabled = true>{{x.comments}}</textarea>
</td>
<td ng-show = "x.status_flag == 0">NA</td>
<td ng-show = "x.status_flag == 0">
<button class="btn btn-warning btn-sm waves-effect waves-light" alt="default">Pending</button>
</td>
<td ng-show = "x.status_flag == 1"> <button class="btn btn-success btn-sm waves-effect waves-light" alt="default">Done</button></td>
<td>
<button class="btn btn-danger btn-sm waves-effect waves-light" alt="default" ng-disabled = "x.status_flag == 1" ng-click = "deleteEditParticipants(x.id,x.task_description,x.closure_date,'delete')">Delete</button>
</td>
<td>
<button class="btn btn-primary btn-sm waves-effect waves-light" alt="default" ng-disabled = "x.status_flag == 1" ng-click = "deleteEditParticipants(x.id,x.task_description,x.closure_date,'update')">Update</button>
</td>
</tr>
</tbody>
</table>
After you fix the HTML check if your JS is working and verify if your code is really generating unique IDs

Ng-show not showing product's detail

I'm making an exercise about the AngularJS, and i created a table that will load the data from database, i have a "Detail" button, when i click on that button, it will assign a new row below the row which contain a button i clicked. It's work fine but the problem is when i click the "Detail" button, it the detail of all, i just want it to show the detail of which product i clicked.
Here is my HTML code:
var app = angular.module("dataApp", []);
app.controller("dataExcuteController", function ($scope, $window,$http) {
$http.get('http://localhost:8080/sachonline/public/administrator/theloai/dstheloai').then(function (response) {
$scope.theloai = response.data.message.ds_theloai;
$scope.isLoading = false;
});
$scope.detailtheloai = function (item) {
$scope.showdetail = true;
};
});
<body ng-app="dataApp" ng-controller="dataExcuteController">
<div class="container">
<table class="table table-bordered">
<thead class="text-center">
<th>STT</th>
<th>Tên thể loại</th>
<th>Trạng thái</th>
<th>
<span><i class="fa fa-cog text-muted"></i></span>
</th>
</thead>
<tbody ng-repeat="item in theloai">
<tr>
<td class="text-center">#{{ item.tl_ma }}</td>
<td>#{{ item.tl_ten }}</td>
<td class="text-center" ng-if="item.tl_trangThai==1">
<span><i class="fa fa-check-circle text-success"></i></span>
</td>
<td class="text-center" ng-if="item.tl_trangThai==0">
<span><i class="fa fa-times-circle text-danger"></i></span>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-warning text-white mr-3 pt-0 pl-2 pr-2" ng-click="detailtheloai(item)"><i class="fa fa-info-circle"></i></button>
<button type="button" class="btn btn-sm btn-success text-white mr-3 pt-0 pl-2 pr-2" data-toggle="modal" data-target="#editForm" ng-click="edittheloai($index)"><i class="fa fa-edit"></i></button>
<button type="button" class="btn btn-sm btn-danger text-white pt-0 pl-2 pr-2" ng-click="removetheloai($index)"><i class="fa fa-trash"></i></button>
</td>
</tr>
<tr ng-show="showdetail">
<td colspan="4">
<table class="table table-info table-bordered">
<tbody>
<tr>
<th class="text-right">Mã thể loại:</th>
<td>#{{ item.tl_ma }}</td>
</tr>
<tr>
<th class="text-right">Tên thể loại:</th>
<td>#{{ item.tl_ten }}</td>
</tr>
<tr>
<th class="text-right">Trạng thái:</th>
<td class="text-center" ng-if="item.tl_trangThai==1">
<span><i class="fa fa-check-circle text-success"></i></span>
</td>
<td class="text-center" ng-if="item.tl_trangThai==0">
<span><i class="fa fa-times-circle text-danger"></i></span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<script src="{!!asset('js/showlist.js')!!}"></script>
</body>
You need to store the show value for every item, therefore I propose you this changes:
js:
$scope.detailtheloai = function (item) {
item.showdetail = true;
};
html:
<tr ng-show="item.showdetail">

How to edit datepicker/day.html from uib-datepicker

In the documentation for uib-datepicker there is an option called template-url
<-- https://angular-ui.github.io/bootstrap/#/datepicker -->
This is the content:
<div ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" tabindex="0"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" tabindex="0"></uib-yearpicker>
</div>
But I need modify the template from "uib-daypicker"; I tried copying the template from datepicker/day.html but it's not working because it's a directive... so, what do I have to do?
----EDITED----
Into the library ui-bootstrap-tpls are all the templates:
datepicker.html
day.html
month.html
year.html
datepicker.html :
<div class="uib-datepicker" ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" tabindex="0"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" tabindex="0"></uib-yearpicker>
</div>
day.html:
<table class="uib-daypicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
<th colspan="{{::5 + showWeeks}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
<th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
</tr>
<tr>
<th ng-if="showWeeks" class="text-center"></th>
<th ng-repeat="label in ::labels track by $index" class="text-center"><small aria-label="{{::label.full}}">{{::label.abbr}}</small></th>
</tr>
</thead>
<tbody>
<tr class="uib-weeks" ng-repeat="row in rows track by $index">
<td ng-if="showWeeks" class="text-center h6"><em>{{ weekNumbers[$index] }}</em></td>
<td ng-repeat="dt in row" class="uib-day text-center" role="gridcell"
id="{{::dt.uid}}"
ng-class="::dt.customClass">
<button type="button" class="btn btn-default btn-sm"
uib-is-class="
'btn-info' for selectedDt,
'active' for activeDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
tabindex="-1"><span ng-class="::{'text-muted': dt.secondary, 'text-info': dt.current}">{{::dt.label}}</span></button>
</td>
</tr>
</tbody>
moth.html:
<table class="uib-monthpicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
<th><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
<th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
</tr>
</thead>
<tbody>
<tr class="uib-months" ng-repeat="row in rows track by $index">
<td ng-repeat="dt in row" class="uib-month text-center" role="gridcell"
id="{{::dt.uid}}"
ng-class="::dt.customClass">
<button type="button" class="btn btn-default"
uib-is-class="
'btn-info' for selectedDt,
'active' for ativeDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
tabindex="-1"><span ng-class="::{'text-info': dt.current}">{{::dt.label}}</span></button>
</td>
</tr>
</tbody>
</table>
year.html:
<table class="uib-yearpicker" role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th><button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-left"></i></button></th>
<th colspan="{{::columns - 2}}"><button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button" class="btn btn-default btn-sm uib-title" ng-click="toggleMode()" ng-disabled="datepickerMode === maxMode" tabindex="-1"><strong>{{title}}</strong></button></th>
<th><button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1"><i class="glyphicon glyphicon-chevron-right"></i></button></th>
</tr>
</thead>
<tbody>
<tr class="uib-years" ng-repeat="row in rows track by $index">
<td ng-repeat="dt in row" class="uib-year text-center" role="gridcell"
id="{{::dt.uid}}"
ng-class="::dt.customClass">
<button type="button" class="btn btn-default"
uib-is-class="
'btn-info' for selectedDt,
'active' for activeDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
tabindex="-1"><span ng-class="::{'text-info': dt.current}">{{::dt.label}}</span></button>
</td>
</tr>
</tbody>
</table>
So if you need change any one of those templates you just use the attribute template-url, for example:
<div class="uib-datepicker" ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)">
<uib-daypicker ng-switch-when="day" template-url="template/route/template-day.html" tabindex="0"></uib-daypicker>
<uib-monthpicker ng-switch-when="month" template-url="template/route/template-moth.html" tabindex="0"></uib-monthpicker>
<uib-yearpicker ng-switch-when="year" template-url="template/route/template-year.html" tabindex="0"></uib-yearpicker>
</div>
Only make your changes on the original templates.
Pd: Sorry about my english isn't my native language.

Resources