Wijmo flexgrid scroll automatically on load

Posted by: pritam1995kumar on 25 February 2019, 2:54 am EST

  • Posted 25 February 2019, 2:54 am EST

    Hi,

    In my flexgrid I have several weeks and requirement is to scroll to the current week on load. I am unable do that.

    please find the below stack-blitz link for more information

    https://stackblitz.com/edit/ionic-dk8fkm

  • Posted 26 February 2019, 3:16 am EST

    Hi,

    We could use the initialized event to get the required functionality. Please refer to the following updated sample and let us know if you face any further issues:

    https://stackblitz.com/edit/ionic-bfs99w?file=pages%2Fwijmo-grid%2Fwijmo-flexgrid.ts

    ~Sharad

  • Posted 26 February 2019, 9:33 am EST - Updated 3 October 2022, 8:09 pm EST

    Hi Sharad,

    First of all thank you very much for the response. but i have some doubts

    1. after the scroll the selected cell is coming in the last visible column. can we do something so

      that the selected column should come in the first visible column.

    2. why we have to use set timeout method.

      for ref find the images:

    expected output

    current output

  • Posted 27 February 2019, 2:19 am EST

    1.can we do something so

    that the selected column should come in the first visible column.


    The way, select works is, it scrolls the grid left/right as little as possible to bring the cell completely in view and stop as soon as the cell is in the view, so when scrolling from left to right(in our case), cell will be in view as soon as it is the last column in the view hence the scrolling stops.

    To bring the column as the first column in view, what we could do is first scroll the grid all the way to the right and then use select(), in this case select method would be required to scroll from right to left and hence would stop scrolling as soon as our column becomes the first column in the view.

    Please refer to the following code snippet and updated sample:

    initGrid(grid){
        setTimeout(()=>{
          grid.scrollPosition = {...grid.scrollPosition, x: -grid.scrollSize.width};
          grid.select(new wjcGrid.CellRange(5,15), true);
        });
      }
    

    https://stackblitz.com/edit/ionic-lqfsdv?file=pages/wijmo-grid/wijmo-flexgrid.ts

    2. why we have to use set timeout method.

    It is because the initialized event is fired when the component is initialized by the angular and all its bound properties have been assigned. It still provides no guarantee that the grid’s view would be updated at this point. So using a setTimeout() makes sure that grid’s view is updated before we try to scroll it.

    Hope this clears!!

  • Posted 28 February 2019, 6:25 am EST

    Hi sharad,

    Thanks for the solution for the scroll issue :slight_smile:

    but for the setTimeout issue …here in the stack-blitz there is no processing is done to format grid. But in out use case we are formatting the grid in item-formater.

    So As, we don’t know the exact time that when the grid will be completely rendered in view it’s causing the issue while using the scroll solution you gave.

    Is there some wijmo/Angular method/event where we can know that the grid is loaded in the view completely then we can apply the ```

    wijmo select

    
    Thanks,
    ~pritam
  • Posted 1 March 2019, 12:50 am EST

    Hi Pritam,

    In this case, we could use updatedLayout or updatedView event. Please refer to the following code snippet and updated sample and let us know if you face any further issues.

    initGrid(grid){
        let updatedLayout = function(s, e){
          s.updatedLayout.removeHandler(updatedLayout);
          grid.scrollPosition = {...grid.scrollPosition, x: -grid.scrollSize.width};
          grid.select(new wjcGrid.CellRange(5,15), true);
        }
        grid.updatedLayout.addHandler(updatedLayout);
      }
    

    https://stackblitz.com/edit/ionic-l3umuk?file=pages%2Fwijmo-grid%2Fwijmo-flexgrid.ts

  • Posted 7 March 2019, 3:42 pm EST

    Hi Sharad,

    Thanks again :slight_smile:

    But still I am having some issue with the scroll before assigning the data to the itemsource we are doing some processing and that is taking a bit of time. That senario above code is not solving. I tried to replicate the same in the below link.

    https://stackblitz.com/edit/ionic-kn2mpj

    kindly check and reply.

  • Posted 11 March 2019, 12:50 am EST

    Hi,

    The issue with the sample is that the data is loaded much after the grid is initialized so we need to update the scrollPosition after we load the data in the grid. Please refer to the following updated sample:

    https://stackblitz.com/edit/ionic-mhsh4p?file=pages%2Fwijmo-grid%2Fwijmo-flexgrid.ts

Need extra support?

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

Learn More

Forum Channels