pig.js icon indicating copy to clipboard operation
pig.js copied to clipboard

How to refresh items if delete any single or multiple items from list ?

Open MrShaikh01 opened this issue 4 years ago • 2 comments

MrShaikh01 avatar Jun 19 '20 10:06 MrShaikh01

This library doesn't support re-laying-out while already initialized. I would recommend showing a spinner on the screen, calling disable() and deleting the Pig instance, and then initialize another new Pig() with updated imageData.

schlosser avatar Jun 19 '20 15:06 schlosser

I am working on a page that loads the image list asynchronously from a REST server and wanted to initialize the pig element when the web page initializes and then set the data source when the data is available. To achieve this it would be enough to add the following 2 methods to pig.js:

setImageData(imageData) {
  this.images = this._parseImageData(imageData);
}

clearImageData() {
  this.images.forEach(image => {
    if (image.existsOnPage) {
      image.hide();
    }
  });
  this.images = this._parseImageData([]);
  this.container.style.height = 'auto';
}

To show the new data, when they get available, I use these lines:

pig.disable();
pig.clearImageData();
pig.setImageData(serverResponseData);
pig.enable();

Seems not to complicated and IMHO would be a nice addition to this great project. Or is this just a complicated way of creating a new pig instance (but I had to remove the images already on the screen anyway).

Besides this, when working on this topic, I stumbled across a property of the pig class: visibleImages. I didn't find any references to this property. Is this just a remnant of an older version? Or did I just not look thoroughly enough?

BePo65 avatar Nov 08 '21 17:11 BePo65