Dealing with hefty JSON documents using iron-ajax, iron-list, and loading with iron-scroll-threshold

I'm facing an issue while attempting to load a large JSON file into my view that contains over 1000 items. My goal is to have the view import only 20 items at a time. However, every time I utilize iron-list, it only renders 3 items initially until I resize the window, after which it loads all the items from the JSON file at once.

Does anyone know of a solution to render 20 items first and then dynamically load more items as I scroll to the bottom?

Thank you in advance.

<dom-module id="fetch">
  <template>
    <style>
      :host {
        display: block;
      }
      paper-card{
        margin-bottom: 1em;
        padding: 1em;
      }
    </style>
    <h2>Hello [[prop1]]</h2>
    <content class="horizontal">
      <paper-material>
          <iron-ajax
              auto
              url="/some.json"
              handle-as="json"
              last-response="{{ajaxResponse}}"
              debounce-duration="300"></iron-ajax>

<iron-scroll-threshold on-lower-threshold="loadMoreData" id="threshold">
        <iron-list items="[[ajaxResponse]]" scroll-target="threshold">
          <template>
            <paper-card>
              <div id="card-content">
                <h4>User:{{item.val}}</h4>
                <h4>{{item.val2}}</h4>
              </div>
              <div class="card-action">
                <paper-button>Icon</paper-button>
                <paper-button>Like</paper-button>
                <paper-fab>Open</paper-fab>
              </div>
            </paper-card>
          </template>
        </iron-list>
      </iron-scroll-threshold>
      </paper-material>
    </content>
  </template>

  <script>

    Polymer({
      is: 'fetch',

      properties: {
        prop1: {
          type: String,
          value: 'fetch'
        },
      }
    });
  </script>
</dom-module>

Answer №1

It seems like the container (

<content class="horizintal>
) of your iron-list may not have a specified size, potentially causing some issues.

As per the information provided in the documentation:

It is crucial that iron-list is either given an explicit size or it should be within a parent element that has an explicitly defined size for scrolling to work properly. By "explicitly sized", it means having a specific CSS height property set using a class or inline style, or being sized through other layout methods like flex or fit classes.

Alternatively, you can trigger a resize event when setting the data:

document.querySelector('iron-list').fire('iron-resize');

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

Submit a set of form variables to PHP using AJAX

I am attempting to transmit a set of form parameters to a PHP script for processing. In the past, I have achieved this using $.post, but now my goal is to accomplish it exclusively with $.ajax. Below is the jQuery click event designed to send all variabl ...

Animating fjdxsu using Threejs formula

Can you provide me with the exact formula that should be used in the animate function? ...

Bespoke HTML, CSS, JavaScript, and PHP website designs within the Wordpress platform

I am a beginner in the world of Wordpress, coming from a background of creating websites from scratch. Currently, I am working on a Wordpress template (Astra) and looking to create a custom page using HTML, CSS, JavaScript, and PHP from the ground up to ad ...

Determine whether an element has the capability to hold text content

Is there a surefire and reliable method to determine if an HTML element is capable of holding text, using only pure JavaScript or jQuery? For example, <br>, <hr>, or <tr> cannot contain text nodes, whereas <div>, <td>, or < ...

When using `console.log`, the object is displayed correctly. However, an error occurs when

Here is the code I've been working on: function parseJSONData(jsonData){ var property, type, name, identifier, comment, content; for(property in jsonData){ switch(property){ case "type": type = jsonData[ ...

An unexpected JavaScript error has occurred in the main process: TypeError - not enough arguments provided

During my attempt to package an electron project using the electron-packager npm module, I encountered an error when running the .exe file of the packaged product. The error specifically references app/dist/packaged-app-win32-x64... and you can see the err ...

Utilizing jQuery to generate dynamic nested divs within the ul li tags

I am looking to dynamically generate nested divs within a ul li. The goal is to create the following structure programmatically: <ul> <li> <div class="videoThumbnail"> <img src="./img6.jpg" /> &l ...

Eliminate specific content from within a div tag

Looking for a solution with the following HTML. <div id="textDiv"> <p> MonkeyDonkey is not a bird. Monkey is an animal. </p> </div> In this case, I am trying to delete the word "Donkey". I attempted the code below but it did no ...

Enhance the table using Django URL tag along with JQuery

I am currently working on a table that is being populated with user details and I would like to include a Django URL tag within the row, extracting the primary key in the process. Here is an example of what I am trying to achieve: function putTableData(re ...

Sharing information between React components involves passing data as props. By sending data from

Brand new to React and still figuring things out. Here's the scenario: <div> <DropDown> </DropDown> <Panel> </Panel> </div> After selecting a value in the dropdown and storing it as currentL ...

Ajax produces a complete reload of the page

I have been working on implementing Ajax functionality to a form that includes a button. The goal is for the form to be submitted when the button is clicked, without causing a page reload. Currently, the issue I am facing is that it reloads the entire pag ...

The building of the module was unsuccessful due to a failure in the babel-loader located in the webpack module of Nuxt

While working on my Nuxt.js project, I encountered a warning error that I couldn't resolve even after searching for a solution. If anyone can assist me with this issue, it would be greatly appreciated. The error message is as follows: ERROR in ./.nu ...

The onkeyup event is not functioning properly, whereas the onchange event is working

I have encountered an issue where both the onkeyup and onchange functions are present on the same page. The problem arises when the onchange function performs an action, causing the onkeyup function to not respond accordingly. However, if I do not interact ...

The function of disabling a form is not affected by the use of jquery $.post

$('#com_form').submit(function(){ var ele = $(this); $.post("includes/agenda_com.php", { text : ele.find('textarea').val(), id : ele.find('#agenda_id').val(); }, fun ...

Interaction between elements in Object3D

I have a collection of objects grouped together in Object3D and I'm attempting to detect when they are clicked on. My scene has dimensions of 600x400, my camera is part of a three-object, and the code for handling events looks like this: function onD ...

Transfer information from a server to a client using the fetch API in pure JavaScript

Hey there, I've been working on a mini app that sends a fetch request to the backend and expects some information in return when a button is clicked. However, I'm facing an issue where the fetch call seems successful with a 200 status, but the d ...

After executing the controller function in AngularJS, the loading icon transitions into a status icon

Is it possible to dynamically change an icon in my view based on the status of a controller function? I want the icon to initially display as a spinning wheel to indicate loading and activity while the function is executing. https://i.stack.imgur.com/I ...

Executing PHP code on button click in HTMLThe process of running a PHP script when

I am currently working on a project that involves detecting facial expressions using Python. However, I need to pass an image to this code through PHP. The PHP code provided below saves the image in a directory. How can I trigger this code using an HTML ...

What steps can I take to ensure that this input is neat and tidy

I need to implement conditional styling for my input field. The current layout is chaotic and I want to improve it. Specifically, when the active item is "Height", I only want to display the height value and be able to change it using setHeight. const [a ...

Tips for effectively handling numerous events from multiple Slickgrid instances on a single page

I'm encountering an issue with utilizing multiple Slickgrids on a single page. With the number of grids changing dynamically, I generate them within a JavaScript function and maintain them in a grid array as shown below. var columns = []; var options ...