NeXTs / Clusterize.js

Tiny vanilla JS plugin to display large data sets easily
https://clusterize.js.org
MIT License
7.22k stars 412 forks source link

redundant rerendering on first time scroll #83

Closed kamax1 closed 8 years ago

kamax1 commented 8 years ago

When scrolling the table for the first time the cluster rerenders and content has bad flashing effect.

I investigated the problem. In my case problem in method getRowsHeight at line opts.item_height = nodes[Math.floor(nodes.length / 2)].offsetHeight; opts.item_height equals 0 during initialization (but nodes exists) so method getClusterNum return Infinity because of division by zero

i've added hot fix

    getClusterNum: function () {
      this.options.scroll_top = this.scroll_elem.scrollTop;
      if (this.options.cluster_height == this.options.block_height) return 0;
      return Math.floor(this.options.scroll_top / (this.options.cluster_height - this.options.block_height)) || 0;
    }

now it works fine for me. Would be cool if you can fix it right way.

I'm using clusterize as directive in Vuejs framework.

NeXTs commented 8 years ago

Hey

opts.item_height equals 0 during initialization (but nodes exists)

how this could be possible if nodes exists? could you please create example at codepen?

kamax1 commented 8 years ago

Here is an example. http://codepen.io/anon/pen/ORNagp I've figured out that it's caused by async loading of data and changing between different states.

NeXTs commented 8 years ago

Whoa, great catch @kamax1 !

NeXTs commented 8 years ago

Just pushed v0.17.1

Try this http://codepen.io/NeXTs/pen/GjkVoO?editors=1010

Pay attention how I changed html and loaded. If your version was important to you - use it, but there would be additional height determination (because until loaded is false - vue doesn't render table so Clusterize could not determine row's height. And will actually investigate row by triggering scroll (when obviously investigation of row height during .update is preferred))

kamax1 commented 8 years ago

Thank you for the fast response. Works perfectly!