0

I am trying to use inifinite-scroll directive for angularJS. The examples show usage of div inside the div, but in my case I'm trying to use it in a table. Here is my html:

<div class="scrolling-table-body">
                    <table class="table table-bordered table-hover table-list">
                        <thead search-table-header data-table="duplicatesTable"
                               data-search="sort(column)"
                               data-show-row-selector="true"
                               data-hide-sorting-indicator="true"
                               data-row-selector-click="selectAllRows(allSelected)"
                               data-column="column">
                        </thead>
                        <tbody infinite-scroll="loadMore()">                            
                            <tr ng-repeat="row in duplicatesArray"
                                
                                ng-click="selectedDuplicateIndex=$index;"
                                ng-class="{selected: $index === selectedDuplicateIndex}">
                                <td style="text-align:center;">
                                    <input type="checkbox"
                                           name="checkRow"
                                           ng-model="row.isSelected"
                                           ng-change="selectRow(row, $index);" />
                                </td>
                                <td>
                                    <span ng-if="row.barcode>0">{{row.barcode}}</span>
                                    <span>{{$index}}</span>
                                    <span class="pull-right">
                                        <i class="fa fa-trash"
                                           style="color:red;"
                                           ng-click="removeRow($index)"
                                           title="@Labels.delete"></i>
                                    </span>
                                </td>
                                <td>
                                    <div class="col-xs-12">
                                        
                                        <input type="text"
                                               name="assetNo"
                                               id="assetNo"
                                               ng-model="row.assetNo"
                                               class="form-control"
                                               ng-change="checkAssetNo(row)"
                                               ng-maxlength="100"
                                               sm-duplicate-validator
                                               validate-duplicates="true"
                                               error-message="row.errorMessage"
                                               api-method="api/rentalEquipments/checkForDuplicate"
                                               primary-key-value="row.equipmentId"
                                               ng-model-options="{  debounce: { default : 500, blur: 0 }}" />
                                    </div>
                                </td>
                                <td>
                                    <input type="text"
                                           name="serialNo1"
                                           id="serialNo1"
                                           ng-model="row.serialNo1"
                                           class="form-control"
                                           ng-maxlength="100" />
                                </td>

The above is used inside the modal form (bootstrap modal).

I initially load 10 rows into my duplicatesArray and I have the following code for loadMore function:

$scope.loadMore = function () {

                    const last = $scope.duplicatesArray.length;
                    if (last < $scope.numberOfDuplicates) {
                        for (let i = 1; i <= 10; i++) {

                            self.logInfo("Loading more duplicates...");
                            const newEquipment = {

                                equipmentId: (last + i) * -1,
                                descrip: self.model.descrip,
                                homeShopId: self.model.homeShopId,
                                ruleId: self.model.ruleId,
                                manufacturerId: self.model.manufacturerId,
                                modelId: self.model.modelId,
                                typeId: self.model.typeId,
                                levelId: self.model.levelId,
                                equipSize: self.model.equipSize,
                                bootMm: self.model.bootMm,
                                bindingManufacturerId: self.model.bindingManufacturerId,
                                bindingModelId: self.model.bindingModelId,
                                cost: self.model.cost,
                                bindingCost: self.model.bindingCost,
                                unitCost: self.model.unitCost,
                                errorMessage: "",
                                duplicateForm: true,
                                duplicatedId: self.model.equipmentId,
                                isDuplicate: true,
                                barcode: 0,
                                assetNo: "",
                                serialNo1: "", serialNo2: "", serialNo3: "", serialNo4: "",
                                isSelected: false
                            };
                            $scope.duplicatesArray.push(newEquipment);
                        }
                    
                }
            };

There is currently an issue in this js code (I moved check for last < numberOfDuplicates before the loop thinking it may be the issue).

When I open my modal I see 20 items in the list and when I scroll I don't see more items.

Do you see what am I doing wrong?

Also, does it matter that I have the following markup for the modal:

<ng-form name="equipmentDuplicatesForm">
        <div class="modal-body">
            
            <div id="fixed-header-table">
                <div class="fixed-header-bg">                    
                </div>
                <div class="scrolling-table-body">
              table goes here
    
     </div>

        <div class="modal-footer hundred-percent padTop padBottom">
            <button type="button" class="btn btn-warning"
                    data-dismiss="modal" aria-hidden="true"
                    ng-click="$dismiss()">
                @Labels.cancel
            </button>

        </div>
    </ng-form>
Naomi
  • 718
  • 1
  • 9
  • 28
  • 1
    Is the `$scope.loadMore()` function definitley getting called? – MikeS Mar 19 '19 at 12:20
  • I can see in console 10 Loading more duplicates... even though I haven't scrolled yet. When I scroll, I don't see any extra messages in console. I can put a break into the function to see if it's called. – Naomi Mar 19 '19 at 12:34
  • I put break into this function and I don't see it is calling at all when I scroll. It is defined in the controller's scope of my modal form. I can try defining it on the main controller instead. – Naomi Mar 19 '19 at 12:38
  • So, why is it initially called twice? In my table the header is a directive using ng-repeat as well, but I tried to add that directive on the tbody tag. I could not find any documentation is that is the supported usage. Also, does it matter that I have a fixed footer at the bottom of my modal form? – Naomi Mar 19 '19 at 14:35
  • 1
    Its difficult to identify without a working example but its very likley the `$scope.loadMore()` gets called on page load and then again because there is available space to load another 10 records - after that is may be a CSS/layout issue where its not detecting the bottom of the div/table correctly – MikeS Mar 19 '19 at 16:02
  • I think you most likely right, but I'm not sure how to make it work. I'm thinking now - may be instead of the infinite scroll I better implement paging instead. – Naomi Mar 19 '19 at 16:57

0 Answers0