Reputation: 105
In following codepen I have two tables simulating a IT trouble ticketing data.
Everything works good for filtering based on either spans (All, Open, Closed) elements and text search. But, one of the tickets has a status of Acknowledge instead of either Open or Closed.
When you click Open I would like the Acknowledged status to be also included.
How can include the status of Acknowledged in my filtering function when the Open span element is clicked?
Thank you.
Here is my HTML:
<div class="container" ng-app="myApp" ng-controller="myController">
<div class="row row-table">
<div class="col-12">
<div class="row">
<div class="col-6 my-auto">
<span ng-repeat="tab in tabsA" ng-click="updateA(tab.value)">{{tab.label}}</span>
</div>
<div class="col-6 my-auto">
<label class="my-auto float-right">Search:
<input ng-model="var2">
</label>
</div>
</div>
<div class="row table-responsive">
<table id="searchTextResults" class="table table-striped">
<tr>
<th ng-click="sortBy('ID')">ID</th>
<th ng-click="sortBy('Description')">Ticket Description</th>
<th ng-click="sortBy('Status')">Ticket Status</th>
<th>Edit</th>
</tr>
<tr ng-repeat="ticket in ticketsA | filter:var2 | filter:searchTextA:true:Status | orderBy:sortField:reverseOrder">
<td><a href="#">{{ticket.ID}}</a></td>
<td><a href="#">{{ticket.Description}}</a></td>
<td><a href="#">{{ticket.Status}}</a></td>
<td><button ng-click="openModal()" class="myBtn">Edit</button></td>
</tr>
</table>
</div>
</div>
</div>
<br>
<div class="row row-table">
<div class="col-12">
<div class="row">
<div class="col-6 my-auto">
<span ng-repeat="tab in tabsB" ng-click="updateB(tab.value)">{{tab.label}}</span>
</div>
<div class="col-6 my-auto">
<label class="my-auto float-right">Search:
<input ng-model="var3">
</label>
</div>
</div>
<div class="row table-responsive">
<table id="searchTextResults" class="table table-striped">
<tr>
<th ng-click="sortBy('ID')">ID</th>
<th ng-click="sortBy('Description')">Ticket Description</th>
<th ng-click="sortBy('Status')">Ticket Status</th>
<th>Edit</th>
</tr>
<tr ng-repeat="ticket in ticketsB | filter:var2 | filter:searchTextB:true:Status | orderBy:sortField:reverseOrder">
<td><a href="#">{{ticket.ID}}</a></td>
<td><a href="#">{{ticket.Description}}</a></td>
<td><a href="#">{{ticket.Status}}</a></td>
<td><button ng-click="openModal()" class="myBtn">Edit</button></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
</div>
</div>
<!--filter:searchText:true:Status |-->
Upvotes: 0
Views: 36
Reputation: 116
var app = angular.module('myApp', []);
app.controller('myController',
function ($scope, $http) {
$scope.ticketsA = [
{
"ID": "001",
"Date": "1/11/2001",
"Description": "Domain Unavailable Error",
"Status": "Open"
},
{
"ID": "002",
"Date": "1/11/2001",
"Description": "Install Open Source Software",
"Status": "Closed"
},
{
"ID": "003",
"Date": "1/11/2001",
"Description": "No key for Closed drawer",
"Status": "Open"
},
{
"ID": "006",
"Date": "1/11/2001",
"Description": "Internal Server Error",
"Status": "Acknowledged"
},
{
"ID": "007",
"Date": "1/11/2001",
"Description": "New Printer",
"Status": "Open"
}
];
$scope.ticketsB = [
{
"ID": "001",
"Date": "1/11/2001",
"Description": "Domain Unavailable Error",
"Status": "Open"
},
{
"ID": "002",
"Date": "1/11/2001",
"Description": "Install Open Source Software",
"Status": "Closed"
},
{
"ID": "003",
"Date": "1/11/2001",
"Description": "No key for Closed drawer",
"Status": "Open"
},
{
"ID": "004",
"Date": "1/11/2001",
"Description": "Pin Reset Needed",
"Status": "Closed"
},
{
"ID": "006",
"Date": "1/11/2001",
"Description": "Internal Server Error",
"Status": "Closed"
},
{
"ID": "007",
"Date": "1/11/2001",
"Description": "New Printer",
"Status": "Acknowledged"
}
];
$scope.countA = $scope.ticketsA.length;
$scope.countB = $scope.ticketsB.length;
$scope.reverseOrder = true;
$scope.sortField = 'ID';
$scope.sortBy = function(sortField) {
$scope.reverseOrder = ($scope.sortField === sortField) ? !$scope.reverseOrder : false;
$scope.sortField = sortField;
};
$scope.var2="";
$scope.var3="";
$scope.tabsA = [
{ value: undefined, label: 'All' },
{ value: ['Open','Acknowledged'], label: 'Open'},
{ value: 'Closed', label: 'Closed'}
];
$scope.tabsB = [
{ value: undefined, label: 'All' },
{ value: ['Open','Acknowledged'], label: 'Open'},
{ value: 'Closed', label: 'Closed'}
];
$scope.updateA = function(filterText) {
if(!filterText){
$scope.searchTextA = filterText;
} else {
$scope.searchTextA = function(e) {
return (filterText.indexOf(e.Status) !== -1);
};
}
};
$scope.updateB = function(filterText) {
if(!filterText){
$scope.searchTextB = filterText;
} else {
$scope.searchTextB = function(e) {
return (filterText.indexOf(e.Status) !== -1);
};
}
};
$scope.openModal = function() {
debugger
modal.style.display = "block";
}
});
// Get the modal
var modal = document.getElementById('myModal');
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
console.log("button clicked");
if (event.target == modal) {
modal.style.display = "none";
}
}
body {
margin: 10px;
}
.row-table {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
span {
margin: 10px;
cursor: pointer;
}
span:hover {
background-color: black;
color: white;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container" ng-app="myApp" ng-controller="myController">
<div class="row row-table">
<div class="col-12">
<div class="row">
<div class="col-6 my-auto">
<span ng-repeat="tab in tabsA" ng-click="updateA(tab.value)">{{tab.label}}</span>
</div>
<div class="col-6 my-auto">
<label class="my-auto float-right">Search:
<input ng-model="var2">
</label>
</div>
</div>
<div class="row table-responsive">
<table id="searchTextResults" class="table table-striped">
<tr>
<th ng-click="sortBy('ID')">ID</th>
<th>Date</th>
<th ng-click="sortBy('Description')">Ticket Description</th>
<th ng-click="sortBy('Status')">Ticket Status</th>
<th>Edit</th>
</tr>
<tr class="clickable_row" ng-repeat="ticket in ticketsA | filter:var2 | filter:searchTextA:true:Status | orderBy:sortField:reverseOrder">
<td>{{ticket.ID}}</td>
<td>{{ticket.Date}}</td>
<td>{{ticket.Description}}</td>
<td>{{ticket.Status}}</td>
<td><button ng-click="openModal()" class="myBtn">Edit</button></td>
</tr>
</table>
</div>
</div>
</div>
<br>
<div class="row row-table">
<div class="col-12">
<div class="row">
<div class="col-6 my-auto">
<span ng-repeat="tab in tabsB" ng-click="updateB(tab.value)">{{tab.label}}</span>
</div>
<div class="col-6 my-auto">
<label class="my-auto float-right">Search:
<input ng-model="var3">
</label>
</div>
</div>
<div class="row table-responsive">
<table id="searchTextResults" class="table table-striped">
<tr>
<th ng-click="sortBy('ID')">ID</th>
<th ng-click="sortBy('Description')">Ticket Description</th>
<th ng-click="sortBy('Status')">Ticket Status</th>
<th>Edit</th>
</tr>
<tr ng-repeat="ticket in ticketsB | filter:var2 | filter:searchTextB:true:Status | orderBy:sortField:reverseOrder">
<td><a href="#">{{ticket.ID}}</a></td>
<td><a href="#">{{ticket.Description}}</a></td>
<td><a href="#">{{ticket.Status}}</a></td>
<td><button ng-click="openModal()" class="myBtn">Edit</button></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
</div>
</div>
<!--filter:searchText:true:Status |-->
$scope.tabsA = [
{ value: undefined, label: 'All' },
{ value: ['Open','Acknowledged'], label: 'Open'},
{ value: 'Closed', label: 'Closed'}
];
$scope.updateA = function(filterText) {
if(!filterText){
$scope.searchTextA = filterText;
} else {
$scope.searchTextA = function(e) {
return (filterText.indexOf(e.Status) !== -1);
};
}
};
Upvotes: 1