A
A
Andrey Kosach2015-05-12 12:29:24
Angular
Andrey Kosach, 2015-05-12 12:29:24

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

2 answer(s)
_
_ _, 2015-05-12
@kocakoc

<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; 
        });

    };

Сергей Гаврилов, 2015-05-12
@FireVolkhov

1. Вот тут устанавливаешь в $scope контроллера, поэтому открываются все вкладки

this.showDetails = this.showDetails === false ? true: false;

2. С данными та жа история $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; 
        });

    };

UPD: Вот тебе вариант, если уделить внимание деталям
$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 question

Ask a Question

731 491 924 answers to any question