How to know the wijmo flex grid has finished loading?

Posted by: sumita.sharma on 28 December 2023, 2:12 am EST

  • Posted 28 December 2023, 2:12 am EST

    We are using Angular 15 and Wijmo Flex Grid. I am trying to show a loader till the grid is fully loaded. I have tried using updatedView, loadedRows, and itemsSourceChanged but none of them work as formatItem gets called even after these events. I can’t put the flag in formatItem handler as it is called multiple times (don’t know how to identify which one is the last call of formatItem). How should I identify my grid is loaded and now can stop showing the loader?

  • Posted 28 December 2023, 4:21 pm EST

    Hi Sumita,

    As per our understanding, you want to show a loader inside FlexGrid until the entire data gets fetched from the server and set to the grid. If so, then instead of handling FlexGrid events, you can add and remove the loader before and after the data gets fetched, respectively. You can refer to the below Wijmo Demo for reference:

    https://developer.mescius.com/wijmo/demos/Core/CollectionView/LoadingData/Spinners/angular

    If you have any specific use case, please let us know, and we will try to assist you accordingly.

    Regards

  • Posted 29 December 2023, 1:38 am EST

    Hi Sonu,

    No, forget about the loader I want a boolean flag that should be true when the whole grid is loaded and stay false if the grid is in making.

    I have tried the above solution it’s not working for us as we have a lot of data and we are using formatItem to format some cells. formatIem is being called many times. Can you provide me an event or some way that will let me know that formatIem event is done and won’t be called again and now the grid is fully ready?

    Regards,

    Sumita Sharma

  • Posted 1 January 2024, 4:34 pm EST

    Hi Sumita,

    The formatItem event is invoked multiple times in the Grid during events such as editing, sorting, filtering, and more, for each cell in the grid. Relying on the formatItem event to determine whether the grid is rendered or not is not recommended, unless it is an exceptionally unique use case.

    To help you better, I would need more information about your use case and what you want to achieve through it along with your application structure. This will allow me to suggest an appropriate approach that meets your requirements.

    Regards

  • Posted 2 January 2024, 1:21 pm EST

    Dear Sonu ,

    This is the first post where I had to explain this much to know an event/method that indicates the grid is fully loaded. Below is the HTML and formatItem code. We are loading a few column dynamically :

    <wj-flex-grid

    #flexGrid

    class=“DataGrid DataGridFlexScroll widthClass btn-addreport”

    [itemsSource]=“customData”

    [showMarquee]=“true”

    [showSort]=“true”

    [autoRowHeights]=“true”

    [headersVisibility]=“‘Column’”

    (initialized)=“gridInitialized(flexGrid)”

    [frozenColumns]=“frozenColumnCount”

    [bentoBusyLoader]=“isDataLoading”

    (selectionChanged)=“handleSelectionChanged(flexGrid, $event)”

    >

      <wj-flex-grid-column
        [header]="'Column 1'"
        [binding]="'Column1'"
        [minWidth]="360"
        [width]="'*'"
        [visible]="true"
        [isReadOnly]="true"
        [wordWrap]="true"
      ></wj-flex-grid-column>
      
    
      <wj-flex-grid-column
        *ngFor="let col of colArr"
        [binding]="col.binding"
        header="{{ col.header }}"
        [allowSorting]="false"
        [autoSizeRows]="false"
        [isReadOnly]="true"
        [wordWrap]="true"
      >
        <ng-template
          wjFlexGridCellTemplate
          [cellType]="'Cell'"
          let-cell="cell"
          let-row="row"
          let-item="item"
          [autoSizeRows]="false"
        >
          <bento-checkbox type="checkbox" id="{{ row.index }}_{{ col.binding }}"
          (change)="onCheckBoxChange()" [(ngModel)]="item[col.binding]" />
        </ng-template>
      </wj-flex-grid-column>
    </wj-flex-grid>
    

    Below is the formatItem , we are using it to make the Column header a hyperlink which will open a pop-up on click

    gridInitialized(flexGrid) {

    flexGrid.hostElement.addEventListener(

    ‘keydown’,

    (e) => {

    this.lastPressedKey = e.code;

        // Manually select the nect cell.
        if (e.code === 'Tab') {
          let cell = this.getNextColumnToSelect();
          flexGrid.select(cell.row, cell.col);
          //
          e.preventDefault();
        }
      },
      true
    );
    if (flexGrid.rows) {
      flexGrid.rows.defaultSize = 50;
      flexGrid.columnHeaders.rows.defaultSize = 50;
    }
    flexGrid.formatItem.addHandler((s, e) => {
      
        let val = s.columns[e.col];
       
        if (this.disableHyperlink) {
          e.cell.innerHTML = peerGroup.peerGroupName;
          e.cell.setAttribute('role', 'columnheader');
        } else {
          e.cell.innerHTML =
            '<h2 class="h6 mb-0 DataGrid-heading">' +
            '<a href="" id="' +
            headerId +
            '" role="link" aria-label="' +
            val.header +
            '"data-headerid="' +
            headerId +
            '" data-pgid="' +
            pgId +
            '">' +
            val.header +
            '</a></h2>';
          e.cell.setAttribute('role', 'columnheader');
          let el = e.cell.querySelector('a');
          el.onclick = (et: any) => {
            et.preventDefault();
            let dataSet = et.target.dataset;
            console.log(dataSet);
            this.showPopUp(dataSet);
          };
        }
      
    });
    
    this.flexGrid = flexGrid;
    let filter = new wjcGridFilter.FlexGridFilter(this.flexGrid);
    this.gridFilter = filter;
    

    }

  • Posted 2 January 2024, 6:05 pm EST

    Hi Sumita,

    To know the state of FlexGrid when it is fully loaded, we have various events for different states of the grid, such as:

    • The “loadedRows” event, is triggered when bound data undergoes changes and internal loading is completed.
    • The “updatedView” event, is triggered upon the grid’s creation/update of elements within the current view range.
    • The “updatedLayout” event, is initiated after the grid updates its internal layout.

    To determine when the grid is fully loaded, consider handling the “updatedView” event. Since this event may be triggered on various events, you can employ a flag that is updated in the “loadedRows” event. This approach ensures that the code within the “updatedView” event is executed only when the underlying bound data is updated. Please refer to the sample link below for reference:

    https://stackblitz.com/edit/angular-f2qeev?file=src%2Fapp%2Fapp.component.ts

    Regards

  • Posted 3 January 2024, 2:42 pm EST

    Hi Sonu ,

    Thanks for replying. I checked the code you provided I am still not sure how the flag is useful - when should we say the grid is loaded? when gridLoadedFlag = true. Because in my code when implemented the last value after the grid is loaded fully gridLoadedFlag = false. If possible in the sample you have provided can you show a message based on the gridLoadedFlag when the grid is loading and is loaded using the gridLoadedFlag ? I think then I will be able to understand how to use the flag.

    Regards,

    Sumita Sharma

  • Posted 4 January 2024, 1:51 am EST

    Hi Sonu,

    Requesting you to please reply ASAP as we have a production release and this is one of the major bugs we have. Thank in advance

    Regards,

    Sumita Sharma

  • Posted 4 January 2024, 5:15 pm EST

    Hi Sumita,

    Sorry for the delayed response. I have updated the sample to show the loading and loaded states through the log. As mentioned earlier, you can use the updatedView event to determine whether the grid has fully loaded. The flag is used to keep the execution of the updatedView event limited to only when the bound data gets changed because the updatedView event gets triggered on multiple events in the grid

    https://stackblitz.com/edit/angular-3iaxko?file=src%2Fapp%2Fapp.component.ts

    Regards

  • Posted 5 January 2024, 8:55 am EST - Updated 5 January 2024, 9:01 am EST

    Hi Sonu,

    I implemented the same code , but the updatedView is being called multiple times. See the image attached. I have added :

    loadedRows(grid) {

    console.log('Grid Loding(loadedRows): ', new Date().getMilliseconds());

    this.gridLoadedFlag = true; //set flag to validate change in bound data

    }

    updatedView(grid) {

    if (!this.gridLoadedFlag) {
      return;
    }
    //Write code here which needs to be executed after Grid gets fully loaded
    console.log('Grid Loaded(updatedView): ', new Date().getMilliseconds());
    this.gridLoadedFlag = false;
    

    }

    Need your input , what is happening

  • Posted 7 January 2024, 7:37 pm EST

    Hi Sumita,

    The observed behavior is expected. As explained previously, the loadedRows event gets triggered whenever the bound data rows get changed, and as we are setting the flag inside the loadedRows event, the updatedView event code also gets executed.

    In case you only want to check the grid-loaded state initially (only when the grid renders initially), then you can set the flag variable inside the initialized event instead of the loadedRows event. You can refer to the updated sample link below for reference:

    https://stackblitz.com/edit/angular-w4x4w5?file=src%2Fapp%2Fapp.component.ts

    Regards

  • Posted 8 January 2024, 10:08 am EST - Updated 8 January 2024, 10:23 am EST

    Hi Sonu ,

    The solution provided is not working, please find the attached screenshots the console messages are shown before the grid is loaded. This is taking a lot of time and we have production release by 13th Jan . Is there a possibility to get into a call or some other way to expedite it?

    Regards,

    Sumita Sharma

  • Posted 8 January 2024, 5:14 pm EST

    Hi Sumita,

    Apologies, but we’re currently unable to reproduce the issue on our end. To help us better understand and address your issue, could you kindly share a concise sample that replicates the issue? so that we can debug it on our end and assist you accordingly.

    If sharing the code on the forum is not feasible, please submit your application code through the support ticket. You can create a new ticket by logging into your Mescius account and navigating to ‘My Support’ > ‘My Cases’. Additionally, we can discuss scheduling a meeting to resolve the issue through the support ticket in case a meeting is necessary.

    Regards

Need extra support?

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

Learn More

Forum Channels