Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ng-grid paging
Message
 
 
General information
Forum:
Javascript
Category:
Other
Title:
Miscellaneous
Thread ID:
01609778
Message ID:
01609819
Views:
31
Did you see my response to you with the code? Do you see obvious problem or need a bit more code? The strange thing is that grid shows info as soon as I activate Developers tools. When I open another account, it again comes up empty and again shows the rows only after deactivating the tools (which were already opened).

>Two questions:
>
>Why are you using a timeout() ?
>
>I don't see anything there that actually populates the grid so what is $scope.setPagingData() ?
>
>
>>Hi everybody,
>>
>>I'm working on this 2 days and I am missing something simple, I believe.
>>
>>Here is my current code:
>>
>>
>>  $scope.getPagedDataAsync = function (pageSize, page, searchText) {
>>                    setTimeout(function () {
>>                        var data;
>>                        if ($scope.currentAccount) {
>>                            //var acctNameHash = $scope.currentAccount.acctNameHash;
>>                            //var showFinalized = $scope.showFinalized;
>>                            var largeLoad = $scope.currentAccount.invoices;
>>                            if (searchText) {
>>                                var ft = searchText.toLowerCase();
>>                                //$http.get('/api/accounts/getAccountInvoices/' + acctNameHash + '/' + showFinalized)
>>                                //    .success(function (largeLoad) 
>>                                {
>>                                    data = largeLoad.filter(function (item) {
>>                                        return JSON.stringify(item).toLowerCase().indexOf(ft) != -1;
>>                                    });
>>                                    // Always use first page after applying a filter
>>                                    $scope.setPagingData(data, 1, pageSize);
>>                                };
>>                            } else {
>>                                //$http.get('/api/accounts/getAccountInvoices/' + acctNameHash + '/' + showFinalized)
>>                                //    .success(function (largeLoad)
>>                                {
>>                                    $scope.setPagingData(largeLoad, page, pageSize);
>>                                }
>>                                //);
>>                            }
>>                        }
>>                    }, 100);
>>                };                
>>
>>                $scope.$watch('pagingOptions', function (newVal, oldVal) {
>>                    if (newVal !== oldVal && newVal.currentPage !== oldVal.currentPage) {
>>                        $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
>>                    }
>>                }, true);
>>
>>                $scope.$watch('showFinalized', function (newVal, oldVal) {
>>                    if (newVal !== oldVal && $scope.currentAccount && !$scope.isNew) {
>>                        getAccountInvoices($scope.currentAccount.acctNameHash);
>>                       // This is part of the getAccountInvoices method
>>                       // $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
>>                    }
>>                });
>>
>>                $scope.$watch('filterOptions', function (newVal, oldVal) {
>>                    if (newVal !== oldVal) {
>>                        $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
>>                    }
>>                }, true);
>>
>>                var linkCellTemplate = '<div class="ngCellText" ng-class="col.colIndex()">' +
>>                       '  <a href="{{row.getProperty(col.field)}}">{{row.getProperty(col.field)}}</a>' +
>>                       '</div>';
>>                var balanceCellTemplate = '<div ng-class="{\'field-validation-error\': row.getProperty(col.field) < 0}"><div class="ngCellText">{{row.getProperty(col.field)|currency}}</div></div>';
>>                $scope.gridOptions = {
>>                    data: 'gridData',
>>          //          showFooter: true,
>>                    enableColumnResize: true,
>>                    enableColumnReordering: true,
>>                    enableRowSelection: false,
>>                    enablePaging: true,
>>                    showFooter: true,
>>                    totalServerItems: 'totalServerItems',
>>                    pagingOptions: $scope.pagingOptions,
>>                    filterOptions: $scope.filterOptions,
>>                    //rowTemplate: '<div style="height: 100%" ng-class="{label label-danger pull-right: row.getProperty(\'hidden\') == true}"><div ng-style="{ \'cursor\': row.cursor }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="ngCell {{col.cellClass}}"><div class="ngVerticalBar" ng-style="{height: rowHeight}" ng-class="{ ngVerticalBarVisible: !$last }"> </div><div ng-cell></div></div></div>',
>>                    columnDefs: [
>>                    {
>>                        field: 'invoiceNo', displayName: 'Invoice #',
>>                        width: 70, resizable: true, sortable: true,
>>                        enableCellEdit: false,
>>                        cellTemplate: linkCellTemplate
>>                    },
>>                    { field: 'descrip', displayName: 'Description', width: 200, resizable: true, sortable: true },
>>                    { field: 'created', displayName: 'Date Created', width: 150, resizable: true, sortable: true, cellFilter: "date: 'medium'" },                   
>>                
>>                    {
>>                        field: 'balance', displayName: 'Balance', resizable: true, sortable: true,
>>                        cellTemplate: balanceCellTemplate
>>                    }]
>>                    //,plugins: [new ngGridFlexibleHeightPlugin()]
>>                };
>>            };
>>
>>I tried implementing the paging the way it's described on the ng-grid page. However, I don't want to re-load data always. I loaded data initially into $scope.currentAccount.invoices. I set my grid to use gridData variable.
>>
>>So, something in the GetPagedDataAsync is not correct now as I see that total number of items changes correctly when I check/uncheck the show finalized checkbox, but grid remains empty.
>>
>>When I open developer's tools and go to AngularJs and start to checking the scopes, I eventually see data in the grid. I can not find the exact pattern.
>>
>>I think the problem is in setTimeout but I'm not certain.
>>
>>Do you see what am I doing wrong? I want to load data all data originally and then just go from page to page.
>>
>>Also, the ng-grid example doesn't really show the filtering option although it seems to implement it. I am wondering what should I do to add the filtering option. I want to have a search textbox and be able to type part of the invoice number and see invoices starting with that number.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform