2

I've followed the examples on Smart Table to a 'T'. I'm unable to get Client Side pagination working. The data is loading asynchronously, hence the st-safe-src.

The main issue is that the page length is not reducing to the defined length and none of the buttons are displaying. There are zero errors in the console.

<apex:page standardController="Account" extensions="RegulationOCheckController">

    <apex:stylesheet value="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />

    <apex:includescript value="//code.angularjs.org/1.3.1/angular.js" />
    <apex:includescript value="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.min.js" />
    <apex:includescript value="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.0/lodash.js" />
    <apex:includescript value="//cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.1.8/smart-table.min.js" />

    <script>

        var app = angular.module('RegulationOCheck', ['smart-table', 'ui.bootstrap'])

        app.controller('CompareController', function($scope, DataService){

            DataService.regulationOCheck().then(function(data){

                $scope.collection = data

            })


        })

        app.factory('DataService', ['$q', '$rootScope', function($q, $rootScope){

            var funcs = {}

            funcs.regulationOCheck = function(){

                var deferred = $q.defer()

                RegulationOCheckController.compare(
                    '{!$CurrentPage.parameters.id}',
                    function(result, event){
                        $rootScope.$apply(function(){
                            if(event.statusCode >= 200 || event.statusCode < 300){
                                deferred.resolve(JSON.parse(result))
                            }else{
                                deferred.reject(event)
                            }
                        })
                    },
                    { escape: false }
                )

                return deferred.promise

            }

            return funcs
        }])

    </script>

    <apex:pageBlock >

            <div ng-app="RegulationOCheck" ng-controller="CompareController">

                <table st-safe-src="collection" st-table="displayed" class="smart-table table">
                    <thead>
                        <tr>
                            <th st-sort="accountName">Insider Name</th>
                            <th st-sort="similarity ">% Similarity</th>
                        </tr>
                        <tr>
                            <th colspan="2">
                                <input st-search="accountName" placeholder="search for insider" class="input-sm form-control" type="search" />
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="row in displayed">
                            <td>{{ row.accountName }}</td>
                            <td>{{ row.similarity }}</td>
                        </tr>
                    </tbody>
                    <tfoot>
                        <tr>
                            <td class="text-center"
                                st-pagination=""
                                st-items-by-page="10"
                                st-displayed-pages="7"
                                colspan="2"></td>
                        </tr>
                    </tfoot>
                </table>

            </div>

    </apex:pageBlock>     

</apex:page>
davecalvin
  • 93
  • 6
  • create a plunker demo that reproduces problem – charlietfl Jul 20 '16 at 19:38
  • I am unable to repo the issue in [Plunker](https://plnkr.co/edit/6nreETTabsF4USXupfrJ?p=preview). I'm thinking this issue resides around the digest cycle. I'm using JavaScript remoting to call an Apex service layer that returns data. – davecalvin Jul 21 '16 at 13:37
  • I think your problem is with `RegulationOCheckController`. read this http://stackoverflow.com/questions/23803743/what-is-the-explicit-promise-construction-antipattern-and-how-do-i-avoid-it – svarog Jul 23 '16 at 06:56

1 Answers1

0

Your problem lies inside the DataService factory, you get your data using a deferred constructor instead of utilizing a proper $http call.

You should replace this mess

funcs.regulationOCheck = function(){

            var deferred = $q.defer()

            RegulationOCheckController.compare(
                '{!$CurrentPage.parameters.id}',
                function(result, event){
                    $rootScope.$apply(function(){
                        if(event.statusCode >= 200 || event.statusCode < 300){
                            deferred.resolve(JSON.parse(result))
                        }else{
                            deferred.reject(event)
                        }
                    })
                },
                { escape: false }
            )
            return deferred.promise
        }

With something along the lines of

funcs.regulationOCheck = function(){

            RegulationOCheckController.compare(
                '{!$CurrentPage.parameters.id}',
                function(result, event){
                    $rootScope.$apply(function(){
                        if(event.statusCode >= 200 || event.statusCode < 300){
                            return $q.when(JSON.parse(result))
                        }else{
                            return $q.reject(event)
                        }
                    })
                },
                { escape: false }
            )
        }

or even $http

funcs.regulationOCheck = function() {
    return $http.get("data.json");
}

And avoid using $rootScope.$apply, it will call a digest cycle for all the application and it's totally not necessary for your scenario

Here is a plunker demo

svarog
  • 9,477
  • 4
  • 61
  • 77
  • Due a Salesforce imposed Callout Depth limit I was forced to utilize JavaScript Remoting to call the Apex controller's compare method. Unfortunately this "mess" is necesary. I'm not sure how to get around the Callout Depth limit any other way. I'd love to simply be able to use the $http module. – davecalvin Jul 24 '16 at 03:20
  • can you run the function inside `$rootScope.$apply` without the `$rootScope.$apply` ? – svarog Jul 24 '16 at 07:31
  • Yes I can. I removed the $rootScope.$apply() apply. Also refactored my code as to steer away from the anti-pattern implementation. Still receiving the same issue. The data set is being returned from the web service correctly, but the smart table isn't rendering as expected. I'm not sure how to dig deeper. – davecalvin Jul 25 '16 at 00:19