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

How to update from json data? #28

Closed lharland closed 9 years ago

lharland commented 9 years ago

Hi, I wanted to use the clusterize.update method but couldn't get it working. How does clusterize know how to format the html based on the objects in the Json data?

NeXTs commented 9 years ago

Hi Clusterize can't update specific rows, .update() method expects full list of rows.

For example you have initialized clusterize with

rows: ['<li>1</li>', '<li>2</li>', '<li>3</li>']

If you want to change second tag to be 5, you have to do

.update(['<li>1</li>', '<li>5</li>', '<li>3</li>'])
NeXTs commented 9 years ago

If you need to update list really often - better set verify_change: true while init clusterize.

It will save you from unnecessary DOM update in case when you are located in one cluster but updating row located in another cluster.

KalaiselvanMahendran commented 7 years ago

How can i give JSON Object as input in clusterize.js ?

NeXTs commented 7 years ago

@KalaiselvanMahendran you need to convert your JSON to array of strings. See https://github.com/NeXTs/Clusterize.js/issues/28#issuecomment-114988544

KalaiselvanMahendran commented 7 years ago

@NeXTs if i have millions of records how can i convert all the record as strings? it takes time to put a millions of data into the loop to convert it has a string. Is there any option like directly passing an array of JSON object?

NeXTs commented 7 years ago

I understand that

but clusterise does not process any data. It requires array of tags in strings, so there aren't other ways of providing data except ['1', '2']

You need to find a way to convert your json in non-blocking way, for example partially by "chunks" using setTimeout loop