4
votes

Given this controller and html, the refresh postback is called, but even with data, the table is not updated. Cannot work out why.

angular.module('umbraco').requires.push('smart-table');
app.controller('adminSection.manageUsersController', [
    '$scope', '$http', 'dialogService', function ($scope, $http, dialogService) {
        var ctrl = this;
        ctrl.members = [];
        ctrl.safeMembers = [];
        ctrl.fetchResults = function fetchResults(tableState) {
            $http.post('/umbraco/backoffice/api/members/search', tableState.search.predicateObject || {codeId: null}).then(function (response) {
                ctrl.members = response.data;
                ctrl.safeMembers = [].concat(ctrl.members);
                console.log(ctrl.safeMembers);
            }, function (response) {
                console.log(response);
                alert("There was an error in the CODE back office app.");
            });
        };

    }
]);

<div class="umb-pane" ng-controller="adminSection.manageUsersController as mc">
  <table st-pipe="mc.fetchResults" st-table="mc.members" st-safe-src="mc.safeMembers" class="table table-striped">
    <thead>
    <tr>
      <th st-sort="codeId">Id</th>
      <th>Name / Job Title / Email</th>
      <th>Access Granted</th>
    </tr>
    <tr>
      <th>
        <input st-search="codeId" placeholder="search code id"/>
      </th>
      <th><input st-search="name" placeholder="search name"/> ( <input st-search="email" placeholder="search email"/> ) of <input st-search="employer" placeholder="search employer"/></th>
      <th></th>
      <th></th>
    </tr>
    </thead>
    <tbody >
    <tr ng-repeat="member in mc.safeMembers">
      <td>{{member.codeId}}</td>
      <td>{{member.fullname}} / {{member.employer}} / {{member.email}}</td>
      <td>{{member.codeId}}</td>
    </tr>
    </tbody>
  </table>
</div>

I have followed this example: link to docs

1

1 Answers

1
votes

your repeater should be on the displayed collection (ie members)

<tr ng-repeat="member in mc.members">

And there is no need to update the displayed collection when you fetch your data

        ctrl.fetchResults = function fetchResults(tableState) {
        $http.post('/umbraco/backoffice/api/members/search', tableState.search.predicateObject || {codeId: null}).then(function (response) {
            ctrl.safeMembers = response.data;
        }, function (response) {
            console.log(response);
            alert("There was an error in the CODE back office app.");
        });
    };