Answer the question
In order to leave comments, you need to log in
AngularJS how to update data in only one category?
There is a table of patients that receives data from the database, it is necessary that when you click on the names of the patients, a submenu opens with data on this patient, this is updated but immediately in the entire table.
<table ng-table="tableParams" show-filter="true" class="table">
<tr ng-repeat-start="user in $data">
<td data-title="'Patient'" filter="{ 'Patient': 'text' }" ng-click="getPatientDetails(user.RequestNumInt)">
{{user.Patient}}
</td>
</tr>
<tr ng-repeat-end>
<td>
<ul ng-hide="showDetails">
<li >
<table class="table">
<tr ng-repeat="exam in exams">
<td >{{exam.ExamName}}</td>
</tr>
</table>
</li>
</ul>
</td>
</tr>
</table>
$scope.getPatientDetails = function(RequestNumInt){
this.showDetails = this.showDetails === false ? true: false;
$http.get("api/controllers/LaboratoryController.php?RequestNumInt="+RequestNumInt).success(function(data){
$scope.exams=data;
});
};
$http({
method: 'GET',
url: 'api/controllers/LaboratoryController.php',
params: {'Cornum':232999}
}).success(function(response) {
var data = response;
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 50, // count per page
filter: {
// initial filter
}
}, {
total: data.length, // length of data
getData: function($defer, params) {
// use build-in angular filter
var orderedData = params.filter() ?
$filter('filter')(data, params.filter()) :
data;
$scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve($scope.users);
}
});
});
Answer the question
In order to leave comments, you need to log in
<table ng-table="tableParams" show-filter="true" class="table">
<tr ng-repeat-start="user in $data">
<td data-title="'Patient'" filter="{ 'Patient': 'text' }" ng-click="getPatientDetails(user.RequestNumInt)">
{{user.Patient}}
</td>
</tr>
<tr ng-repeat-end>
<td>
<ul ng-show="detailsUserId === user.RequestNumInt">
<li >
<table class="table">
<tr ng-repeat="exam in exams">
<td >{{exam.ExamName}}</td>
</tr>
</table>
</li>
</ul>
</td>
</tr>
</table>
$scope.getPatientDetails = function(RequestNumInt){
$scope.detailsUserId = $scope.detailsUserId === RequestNumInt ? null : RequestNumInt;
$http.get("api/controllers/LaboratoryController.php?RequestNumInt="+RequestNumInt).success(function(data){
$scope.exams=data;
});
};
1. Вот тут устанавливаешь в $scope контроллера, поэтому открываются все вкладки
this.showDetails = this.showDetails === false ? true: false;
$scope.exams=data;
$scope.getPatientDetails = function(user){
user.$showDetails = user.$showDetails === false ? true: false;
$http.get("api/controllers/LaboratoryController.php?RequestNumInt="+user.RequestNumInt).success(function(data){
user.$exams=data;
});
};
$scope.getPatientDetails = function(user){
if (!user.$showDetails){
$http.get("api/controllers/LaboratoryController.php?RequestNumInt="+user.RequestNumInt).success(function(data){
user.$showDetails = true;
user.$exams=data;
console.log(user.$exams);
});
} else {
user.$showDetails = false;
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question