Ag-grid: data not populating in viewport

Here is part 2 of the question: Ag-grid viewport: cannot read property 'bind' of undefined

Even though I have defined all the necessary functions for the viewport interface, I am still facing difficulties loading data into the grid. You can check out the issue in this plunker:

https://plnkr.co/edit/EEEJULRE72nbPF6G0PCK

Specifically, the following stages mentioned in the documentation do not seem to be triggered:

  1. The datasource responds with the size of the data (e.g. 1,000 rows) and calls params.setRowCount(1000). The grid should adjust its vertical scroll to accommodate 1,000 rows.

  2. The grid determines it can display 20 rows at a time due to its physical size on the screen. With the scroll position at the beginning, it should call datasource.setViewportRange(0,19) to inform the datasource about the needed data. Currently, the grid shows blank rows instead.

I've implemented a function to populate the grid:

WatcherTable.prototype.setRowData =function ($http) {
    // Mock server setup - actual code will interact with your real server
    var mockServer = new MockServer();
    $http.get('data.json').then(function(response){
        mockServer.init(response.data);
    });

    var viewportDatasource = new ViewportDatasource(mockServer);
    var that=this;
    this.table.api.setViewportDatasource(viewportDatasource);
    
    // Delay 'size cols to fit' to consider scrolling
    setTimeout(function () {
        that.table.api.sizeColumnsToFit();
    }, 100);
}

This function is called when the grid is ready:

onGridReady:WatcherTable.prototype.setRowData.bind(this,$http)

However, the grid remains empty. Any insights on why this might be happening?

Thank you!

Answer №1

Your plunker is experiencing a timing issue where the MockServer is attempting to process data before it's available.

To resolve this issue, you should make two adjustments. First, ensure that the data source is only set once the data is ready in the MockServer:

WatcherTable.prototype.setRowData = function ($http) {
    var mockServer = new MockServer();
    var that = this;
    $http.get('data.json').then(function (response) {
        mockServer.init(response.data);
        var viewportDatasource = new ViewportDatasource(mockServer);
        that.table.api.setViewportDatasource(viewportDatasource);

        setTimeout(function () {
            that.table.api.sizeColumnsToFit();
        }, 100);
    });
}

Secondly, to address the periodic updates processing data prematurely, either start the updates after the data is available or implement a check before processing:

MockServer.prototype.periodicallyUpdateData = function() {
    if(!this.allData) return;

I have made the above changes and forked your plunker here: https://plnkr.co/edit/cY30aHIPydVOjcihX8Zh?p=preview

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

I am having trouble modifying the content of a div using Jquery append

I have a plan to use jQuery to change images. I have multiple image files named choose 01.png, choose 02.png, and so on. When an image is clicked, I want it to be replaced with the corresponding choose 01.png file. Once 5 images have been clicked and chang ...

A recent addition to the webpage is causing the script to malfunction

I am experiencing an issue on my website where the radio button does not trigger the onchange event when I reload content in a DIV using (.load()). How can I solve this problem? $(window).ready(function(){ $('input[name="optionsRadios"]').on ...

Switching from using jQuery.ajax() to fetch() when making requests to a Go REST API endpoint with no payload

I have a ReactJS web application that communicates with a REST API endpoint built in golang. Previously, I used jQuery to make Ajax POST requests and it worked perfectly. Here's an example of the code: // Using jQuery let sendUrl = "http://192.168.1 ...

What is preventing setAttribute from successfully setting the class for the li element?

Currently, I am diving into the world of DOM Manipulation. I have successfully created a new li element, but unfortunately, the fontSize styling is not being applied to it as expected. const title = document.querySelector("#main-heading"); title.styl ...

Is it possible to conceal a menu or title on a webpage and have the text automatically show up after a set number of seconds?

For my school project, I came up with an idea that involves hiding the title and menu for a few seconds before displaying them on the webpage. I've been doing some online research on how to achieve this using CSS or JavaScript. I considered using a di ...

Creating a simulated loading screen

I have created a preloader page for my website following tutorials, such as the one found here: https://codepen.io/bommell/pen/OPaMmj. However, I am facing a challenge in making this preloader appear fake without using heavy content like images or videos. ...

Tips for modifying HTML elements and navigating to a different webpage

As I delve into the world of front-end web development, I decided to challenge myself with a little exercise by creating a basic HTML form. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta ...

How can I extract the minimum price from this array list using Reactjs?

In my ReactJS project, I have an array list structured like this. I am trying to find the minimum price from this list. For example, if 'totalll' is 100, how can I achieve that? Please advise on how to navigate through the array to retrieve the i ...

Using a static string in Javascript yields no issues, whereas working with variables can sometimes cause problems

I've been struggling with a problem this morning and it's time to ask for help! I have a JavaScript function that takes the value entered by a user into an autocomplete box, uses AJAX to send that value to a PHP script which then queries the data ...

Preventing User Input in Autocomplete TextField using React Material UI

Currently, I am utilizing the Material UI component Autocomplete to display options. However, I would like for Autocomplete to function more like a select dropdown, where users do not need to type anything to receive suggestions. Is there a way to modify A ...

Inspect every div for an id that corresponds to the values stored in an array

I am in the process of developing a series of tabs based on a preexisting set of categories using the JavaScript code below. Now, I am looking to expand this functionality to target specific IDs within the DIV ID corresponding to values from an array in JS ...

What is the process for creating a tab logo?

Is there a way to create a personalized logo to appear next to the website title on the tab? Whenever I see a logo displayed beside the website title in my browser tabs, I can't help but wonder how it's done. ...

What is the best way to connect a router link and dialog box in a dropdown menu using Vue.js?

https://i.sstatic.net/JahMG.pngI am working on implementing a dropdown menu that includes a router link to another component and a dialog component for a dialog box. Here is the code snippet for reference: <td align="center"> <v-btn ...

Is there a way to alter the text color using JavaScript on the client side?

Is there a way to change the color of a list item in a ul based on whether it is a palindrome or not? Here is the JavaScript file I am working with: function isPalindrome(text){ return text == text.split('').reverse().join(''); } c ...

Changing the default route in Angular 2 based on conditions

I'm currently developing an application where, upon entering the page, the default route for the user is the "Login" page. However, I want to implement a condition based on whether the user has a local storage variable (id) set. If this variable exist ...

The Expressjs router prioritizes resolving before retrieving data from Firestore

UPDATE: Upon further investigation, I discovered that by adding "async" to the function signature, the output now displays in the intended order. However, I am still encountering an error regarding setting headers after they have already been sent, even th ...

Leveraging several useState hooks

When working on a React Native project, I have implemented multiple hooks to retrieve input data in a form. Are there any alternative methods that are more efficient or better suited for this task? Thank you const [name, setName] = useState(''); ...

Is it possible for Javascript, AJAX, or JQuery to determine if a form has been manually inputted into

My goal is to change the contents of a form field and submit the form through the console. However, when I use either jQuery or JavaScript to modify the field and submit it, the page only recognizes values that were manually typed in. In the code snippet ...

Implementing a download hyperlink attribute for a button with jQuery

How can I create a jQuery function for a button? <input type="submit" id="submit"></input> Once clicked, it should trigger the following action: <a download href="file.doc"></a> <script> $("#submit").click(function(){ ...

Trouble sliding with Material UI Slider

I've encountered an issue with my Material UI slider - it doesn't slide when clicked and dragged. I followed one of the examples on the Material UI website (https://material-ui.com/components/slider/) and included an onChange function. The values ...