Adding virtualization in wijmo grid ANGULAR

Posted by: sudhiman on 15 February 2021, 5:28 am EST

  • Posted 15 February 2021, 5:28 am EST - Updated 3 October 2022, 2:29 pm EST

    Hello Team grapecity,

    Wijmo version: 5.20191.605

    Angular version: 5.2

    Following this sample

    https://stackblitz.com/edit/angular-9-0-0-rc-1-9okodj?file=src%2Fapp%2Fapp.component.ts

    Issue facing this:

    1st 20 records load with this console error cannot read property "CurrentPosition "

    while scrolling down, next 20 records not appending, only starting same 20 records remains there in Grid.

    Debugging into it “CurrentPosition” shows 0

    while scrolling, scrollChanged() function is call everytime .

    Please have look in my code I added

    IN HTML:

      <wj-flex-grid #rbiCuiFlexGrid style="height: calc(100vh - 165px);overflow-y: scroll !important;"
                      [(itemsSource)]="[b]data1[/b]"
                      (scrollPositionChanged)="[b]scrollChanged[/b](rbiCuiFlexGrid)"
                      (formatItem)="addGearIcon(rbiCuiFlexGrid, $event)"
                      (initialized)="initializeGrid(rbiCuiFlexGrid)"
                      (loadedRows)="rbiCuiFlexGrid.autoSizeColumns()"
                      [isReadOnly]="true">
            <wj-flex-grid-filter #filter class="row-filter"></wj-flex-grid-filter>
    

    IN TS:

    Variable declaration:

        data1: wjcCore.CollectionView;
        DataList: any[];
    

    In given sample ForLoop is used to create grid records, but here in my case

    we are getting data List from API .

         this.[b]rbiCuiService[/b].getCUIRBIData(this.solvLiveDataModel) 
                    .subscribe(DataGetFromAPI => {
                        this.DataList = DataGetFromAPI;
                        this.subscribeFunction(this.getData(20));
    
                    }
    

    To iterate as per sample , assigned and get data from DataList through loop

        getData(count) {
            let  data = [];
            for (var i = 0; i < count; i++) {
                data.push(
                    this.DataList[i]);
            }
    
    
            return new wjcCore.CollectionView(data);
        }
    

    Created same function as per sample

       private subscribeFunction(view: wjcCore.CollectionView) {
            // if data1 is not defined
            if (!this.data1) {
                // then create it
                this.data1 = view;
            } else {
                // otherwise update items
                let items = view.items;
                Array.prototype.push.apply(this.data1.items, items); // push the new items
                this.data1.refresh();
            }
        }
    
      [b]scrollChanged[/b](s: wjcGrid.FlexGrid) {
    
            // if we're close to the bottom, add 20 items
            if (s.viewRange.bottomRow >= s.rows.length - 1) {
                let view = s.collectionView;
                let index = view.currentPosition; // keep position in case the view is sorted
               // this.getData(10, view.items.length);
                this.getData(20);
                view.currentPosition = index;
            }
        }
    

    Please let me know about this issue facing.

    Thanks in Advance

  • Posted 15 February 2021, 10:05 am EST - Updated 3 October 2022, 2:28 pm EST

  • Posted 16 February 2021, 12:56 am EST

    Hello Team Grapecity, Any update on this ?

  • Posted 16 February 2021, 4:00 am EST

    Hello Grapecity, we need fix for this on priority basis. we are stuck .

    Please look into provide update on it.

  • Posted 16 February 2021, 6:10 am EST

    Hi Sunny,

    According to your code snippet, you will need to call the subscribeFunction method in the scrollPositionChanged handler instead of getData because the does not actually update the original CollectionView which is assigned to the FlexGrid. Please refer to the updated sample below:

    https://codesandbox.io/s/angular-forked-z9x20

    Let me know if this helps.

    Regards,

    Ashwin

  • Posted 16 February 2021, 6:52 am EST - Updated 3 October 2022, 2:29 pm EST

  • Posted 16 February 2021, 7:09 am EST

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels