Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

angularjs ngTable pagination showing all the results in a single page and data is loading every time on same page using API calls #1049

Open
spanchala opened this issue Feb 26, 2021 · 0 comments

Comments

@spanchala
Copy link

spanchala commented Feb 26, 2021

I am using ngTable to load data from the API calls, the page always refreshing and data is showing on same page - which typically have 1000 or more records but since I have several api calls which are coming from the loop over, there could be 0 records or more from each of the calls which are pushed to the final $scope variable. Can you please add pagination to the calls, also when can I determine the loop is done in order to display the final noResultsFoundText found during the 0 records from all the calls. How to do update the pagination to display 10 records per page. Thank you for your help.

Here is the sample code-
` $scope.tableParams = new NgTableParams(
{
page: 1,
count: 10,
sorting: { sequence: "asc" }
}, {
counts: [25, 50, 75, 100],
total: 0,
getData: function (params) {

        $scope.noResultsFoundText = false;
        if (params.page() === 1)/*empty the checkboxes array only if it's a new search*/
            $scope.checkboxes.items = {};

        if ($scope.newSearch) {
            $scope.newSearch = false;
            $scope.clear = false;
            $scope.submitted = false;
            params.filter({});//Clear filters
            $scope.loading = false;

            angular.forEach($scope.registeredStudents, function (student) {
               studentsDataSource.query({ searchData: $scope.searchData, registeredStudent: student }).$promise.then(function (errorCourses) {
                    $scope.errorCourses.push.apply($scope.errorCourses, errorCourses);
                    $scope.errorCourses = params.filter() ? $filter('filter')(errorCourses, params.filter()) : errorCourses;
                    $scope.errorCourses = params.sorting() ? $filter('orderBy')(errorCourses, params.orderBy()) : errorCourses;
                    params.page(1);//With every new search go to the first page
                    params.total(errorCourses.length);
                    $scope.errorCourses = errorCourses.slice((params.page() - 1) * params.count(), params.page() * params.count());
                    $scope.noResultsFoundText = $scope.errorCourses.length > 0 ? false : true;
                });

            });
        
            return $scope.errorCourses`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant