Ag-Grid refreshes scroll position when loading a new data source

I manage my data outside of Ag-Grid related code. I use a variable, this.works, to store all user "portfolio" information for my portfolio manager project. Additionally, I utilize this.loadMore() to fetch more data from the server (which is accessed externally).

To enable infinite scroll, I have implemented the "infinite" row model. I decided to employ a datasource as I also require sorting and filtering functionalities.

The issue arises when I update the datasource; the scrolling resets to the top, which is incredibly frustrating.

This setup utilizes Ag-Grid Community in conjunction with Vue.js.

Here are the GridOptions (set in beforeMount()):

  this.gridOptions = {
    suppressScrollOnNewData: true,
    rowSelection: 'single',
    rowModelType: 'infinite',
    deltaRowDataMode: true,
    defaultColDef: {
      sortable: false,
      resizable: true
    },
    columnTypes: {
      'imageColumn': {
        width: 150,
        sortable: false,
        autoHeight: true,
        cellRendererFramework: AgGridImageFormatter
      },
      'priceColumn': {
        cellRendererFramework: AgGridPriceFormatter
      }
    }
  };

Methods:

({
  methods: {
    onBodyScroll: function(event) {
      var lastDisplayedWork, ref, worksCount;
      worksCount = this.works.length;
      lastDisplayedWork = (ref = this.gridOptions.api) != null ? ref.getLastDisplayedRow() : void 0;
      if (worksCount - 2 < lastDisplayedWork) {
        event.api.ensureIndexVisible(worksCount - 2);
        this.loadMore();
        return event.api.setDatasource(this.gridDatasource);
      }
    },
    CreateAgGridDataSource: function(worksData) {
      return {
        rowCount: this.works.length,
        getRows: (function(_this) {
          return function(params) {
            var lastRow, rowsThisPage;
            rowsThisPage = _this.works.slice(params.startRow, params.endRow);
            lastRow = -1;
            return params.successCallback(rowsThisPage, lastRow);
          };
        })(this)
      };
    },
    onRowSelected: function(event) {
      return this.workClicked(event.data.id);
    },
    onGridReady: function(event) {
      this.gridDatasource = this.CreateAgGridDataSource(this.works);
      return event.api.setDatasource(this.gridDatasource);
    }
  }
});

My apologies for any unconventional JS code; I'm using a CoffeeScript to JS converter. Though, it should function correctly.

HTML:

<div id="gridContainer">
    <ag-grid-vue class="ag-theme-balham" id="AgGrid" :gridOptions="gridOptions" :modules="agGridModules" :columnDefs="agGridColDefs" @body-scroll="onBodyScroll" @row-selected="onRowSelected" @grid-ready="onGridReady"></ag-grid-vue>
</div>

Is there a way to maintain the scroll position where the user left off? Using api.refreshCells() did not yield results as expected. It resulted in empty rows after the initial data call (only displaying around the first ~23 items). Therefore, I need to "refresh" the datasource each time new data is retrieved.

Answer №2

While my solution may not be suitable for everyone, our company made the decision to invest in the Enterprise Ag-Grid. By doing so, we were granted access to the powerful Server Side Row Model feature, allowing us to selectively render specific rows. Through simulating server fetching within the data source fetch function, we are able to efficiently render only the necessary rows returned. This customization is made possible by our enterprise license and is not available in the community edition of Ag-Grid.

Answer №3

Everything is functioning correctly:

gridOptions.api.refreshInfiniteCache()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Axios recursion to paginate through an API using a cursor-based approach

Is there a way to paginate an API with a cursor using axios? I am looking to repeatedly call this function until response.data.length < 1 and return the complete array containing all items in the collection once the process is complete. Additionally, I ...

Updating the color of text when clicking on a link using javascript

I am facing an issue where I cannot seem to change the text color using JavaScript. The functionality to show and hide div tags is working perfectly, but changing the color seems to be a challenge. It's worth noting that there are no styles defined fo ...

Is it possible to customize style based on a key in a v-for loop?

I'm currently working on a small application that changes styles based on keys in a v-for loop. I'm struggling to figure out how to update the style dynamically. My goal is to colorize one as blue, two as green, and three as red. <div id="ap ...

Ending the Overlay

I am using an overlay: <div id="overlayer" class="overlayer"> <div id="board" class="board"></div> </div> Here are the CSS properties I have applied to it: #overlayer { position:fixed; display:none; top:0; left:0; width:100%; hei ...

Ways to eliminate a value once a checkbox is deselected

I am currently developing a search box that includes three separate fields which will be populated with data using AJAX based on the user's selection. Here is the HTML structure I have implemented: <div id="states"> <input type="checkbo ...

Is incorporating atomic design into my Domain-Driven Design approach a practical choice for enhancing the user interface domain?

Just Starting Out with DDD I recently came across two blog posts that discussed the differences between DDD and the MVVM pattern. They also suggested a new folder structure with modules sharing common objects like { app, router, store, eventBus }. My que ...

Contradictory jQuery extensions

After exploring this site as part of my web coding self-study, I decided to register so I could ask a specific question. Currently, I am in the process of developing my new website and ran into an issue on a test page (www.owenprescott.com/home.html). The ...

Is there a method to eliminate the necessity of including the server IP address in the nginx configuration file?

I integrated nginx as a reverse proxy into a basic express app. In the configuration file, I specified the server IP address () as the server_name. However, I am looking for a way to avoid directly inputting the actual server IP in the config file without ...

Tips for choosing a specific value from an object within an array

I'm currently struggling to determine the best way to retrieve a value from an object within my state array. The array in question looks like this: [ { name: bench, weight: 200, percentages: [200,...] }, { name: squat, weight: 300, perc ...

"Exploring the Power of Logarithmic Slider with Vue and Quasar

I'm currently working on a project utilizing Vue 2 and Quasar 1, where I am attempting to develop a logarithmic slider. Initially, I managed to create a basic example using a native input slider in this code pen: https://codepen.io/tonycarpenter/pen/Z ...

Display array elements in a PDF document using pdfmake

Upon reaching the final page of my Angular project, I have an array filled with data retrieved from a database. How can I utilize pdfmake to import this data into a PDF file? My goal is to display a table where the first column shows interv.code and the ...

Tips for building a responsive dropdown menu using data from a database query

Currently, I am fetching a list of companies from Firestore and attempting to display them as options in a dropdown menu. While the companies state is being populated correctly from Firestore, the options are not being created or updated dynamically. How c ...

Troubleshooting Problems with Loading Data into Highcharts using Javascript

The server is returning data in the following format: {"barData": [ {"Accepted":[0,0,0]}, {"Rejected":[0,0,0]}, {"In_Process":[0,1,0]}] } On the browser, it appears as follows: I initially thought that this was the correct st ...

Incorporate Google Analytics in Next.js to load exclusively upon receiving consent

I successfully implemented google analytics in my Next.js project by following these helpful guides: https://github.com/vercel/next.js/tree/canary/examples/with-google-analytics Now, I face a new challenge where I need to ensure that Google Analytics is ...

Having trouble with QuickBlox video calling feature on the web?

I have encountered an issue while trying to integrate video chat into my Java web application using QuickBlox. I am utilizing Angular/JavaScript on the frontend. The problem arises when attempting to create a session for a user that I have created in Quic ...

When you utilize React.createRef, the value of `current` is consistently null

I attempted to follow the steps outlined in this guide. Despite my efforts, I seem to be overlooking something as I can't figure out why current always returns null in this specific scenario. class App extends React.PureComponent { constructor(pro ...

JavaScript's jQuery selector retrieves a child element from one location and adds it to a different

Why does the Jquery children selector select the img element, extract it, remove it, and then append it to another div element? Shouldn't it create a copy of the element being appended? var $anchors = $("#imageGallery a"); var $overlay = $('&l ...

Error message: "Unable to perform Babel on Gulp in Windows 10"

After upgrading my machine from Windows 7 to Windows 10, I encountered an issue with a gulp task I had set up for a project. The task started failing after the upgrade, and I received the following error in the command line: return binding.open(pathModule ...

Can I safely keep a JWT in localStorage while using ReactJS?

As I work on developing a single page application with ReactJS, one question comes to mind. I came across information indicating that using localStorage may pose security risks due to XSS vulnerabilities. However, given that React escapes all user input, ...

Utilizing MongoDB in Node.js Environment

I am currently facing an issue with connecting to a larger database through node. In the past, I have successfully connected to smaller databases using a Mongo URL in this format: mongodb://[username]:[password]@db1-a0.example.net:27017/[DB-Name] However ...