lundi 21 août 2017

Checkbox Unchecking after AngularJS sorting

I currently have a table listing jobs. Each job has a checkbox.

<form name="jobsSampleSelectForm" id="jobs-sample-select-form">
    <div  jobs="data">
      <div ng-form="jobsSampleSelectForm">
        <table ng-table="tableParams" class="table" show-filter="true">
            <tr ng-repeat="job in $data" class="table-highlight" ng-class="{deactivated: job.is_active == 'No'}">
                <td data-title="'Sample'"><input type="checkbox" ng-model="job.selected"></td>
                <td data-title="'QC ID'" sortable="'id'"><a href="#/jobs/"></a></td>
                <td data-title="'Date Submitted'" sortable="'dateJob'"></td>
            </tr>
        </table>
      </div></div>
    <button type="submit" class="btn btn-primary-red" ng-click="sampleJobs()" ng-disabled="(jobs | filter: job.selected != true).length <= 0">Sample Jobs</button>
</form>

This allows the user to select the jobs they want. However, when the user sorts a column the checkbox will uncheck itself. This seems to be a common issue, so from the advice from this SO question I added a selected attribute to each job in my controller.

jobsService.getJobsByStatuses(["pre_sampling", "sampling", "setup"])
    .success(function(data){
        data.forEach(function(job){ job.selected = false; });
        $scope.jobs = data;
        var filteredData = params.filter() ? $filter('filter')(data, params.filter()) : data;
        var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : data;

        $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
        params.total(orderedData.length);
})

This did not seem to cause a difference. What am I missing?




Aucun commentaire:

Enregistrer un commentaire