4

I've got implemented ng-table with an ajax call but never call the function from getdata, the function onBuscarTable is never call, I've look at the debbugger console to check it and dosen't call it:

what i'm doing whrong?

here's the js:

    $scope.onBuscarTable = function ($defer, params) {
    $.ajax({
        type: 'GET',
        url: '/Home/GetEfficiencyDetails',
        cache: false,
        contentType: 'application/json; charset=utf-8',
        //data: JSON.stringify({ title: "fghfdhgfdgfd" }),
        success: function (data) {
            $scope.items = data;
            $defer.resolve(data);
        }
    });
};

//$scope.getEffiencyDetails();
$scope.tableBuscar = new ngTableParams({
    page: 1, // show first page
    count: $scope.items.length, // hides pager
    sorting: {
        name: 'asc' // initial sorting
    }
}, {
    counts: [], // hides page sizes
    getData: $scope.onBuscarTable

});

$scope.tableBuscar.reload();

and here is the html:

                            <table ng-table="tableBuscar" show-filter="true" class="table table-striped table-bordered table-condensed table-hover">

                            <tbody>
                                <tr>
                                    <th colspan="5">Battery Life</th>
                                    <th colspan="4">SBC</th>
                                    <th colspan="3">ZBC</th>
                                    <th>Overall</th>
                                </tr>
                                <tr>
                                    <th>Pool #</th>
                                    <th>True Cap.</th>
                                    <th>Util.</th>
                                    <th>Load Sharing</th>

                                </tr>
                                <tr ng-repeat="item in items">
                                    <td>{{item.PoolName}}</td>
                                    <td>{{item.AvgTrueCapacity}}</td>
                                    <td>{{item.AvgEnergyUsageDaily}}</td>  
                                </tr>                                  

                            </tbody>
                        </table>
Diego Unanue
  • 6,576
  • 8
  • 47
  • 67

1 Answers1

0

You code should using $http instead of $.ajax

$scope.items = [];
$scope.onBuscarTable = function($defer, params) {
    $http.get('/Home/GetEfficiencyDetails').success(function(data) {
        $scope.items = data;
        $defer.resolve(data);
    });
};

//$scope.getEffiencyDetails();
$scope.tableBuscar = new ngTableParams({
    page: 1, // show first page
    count: $scope.items.length, // hides pager
    sorting: {
        name: 'asc' // initial sorting
    }
}, {
    counts: [], // hides page sizes
    getData: $scope.onBuscarTable

});

$scope.tableBuscar.reload();
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • it works but it's call three times, why can it be that? GET http://localhost:4684/Home/GetEfficiencyDetails 200 OK GET http://localhost:4684/Home/GetEfficiencyDetails 200 OK GET http://localhost:4684/Home/GetEfficiencyDetails 200 OK – Diego Unanue Apr 23 '15 at 18:20
  • because using jquery inside angular will not run angular digest, you need to manually update it.. – Pankaj Parkar Apr 23 '15 at 18:22
  • 1
    @DiegoUnanue its calling multiple time because `$scope.tableBuscar.reload();` this line – Pankaj Parkar Apr 23 '15 at 18:22