Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9270767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:27:05+00:00 2026-06-18T15:27:05+00:00

Given a Knockout observableArray, to which items can be added and removed, how do

  • 0

Given a Knockout observableArray, to which items can be added and removed, how do I lay out the corresponding HTML elements with Isotope? Consider for example the following HTML, which declares a div #container that should be populated with child divs by Knockout:

<div id="container" data-bind="foreach: items, click: addItem">
<div class="item show" data-bind="text: text, click: $parent.removeItem, clickBubble: false"></div>

The accompanying JavaScript pre-populates the container with a couple of items, and lets the user click on items to delete them and click in the container to add new items (via Knockout):

function ItemModel(parent) {
    var value, self = this,
        found;
    for (value = 0; value < parent.items().length; ++value) {
        found = false;
        for (i in parent.items()) {
            var item = parent.items()[i];
            if (item.value() == value) {
                found = true;
                break;
            }
        }
        if (!found) {
            break;
        }
    }
    this.value = ko.observable(value);

    this.text = ko.computed(function () {
        return "Item " + self.value();
    });
}

var ViewModel = function () {
    var self = this;
    self.items = ko.observableArray()
    self.items.push(new ItemModel(self));
    self.items.push(new ItemModel(self));

    this.removeItem = function (item) {
        self.items.remove(item);
        return false;
    };

    this.addItem = function () {
        self.items.push(new ItemModel(self));
    };
};

ko.applyBindings(new ViewModel("Test"));

When coupled properly with Isotope, items should be laid out automatically by Isotope, including when items are removed, added and moved.

See this fiddle for a demo of the concept.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:27:07+00:00Added an answer on June 18, 2026 at 3:27 pm

    I have been able to integrate Knockout with Isotope by writing a special Knockout binding, called Knockout-Isotope. This facilitates integrating the two technologies greatly, and makes sure that Isotope stays synchronized with the Knockout view model. See the code below for an example of how to use this binding with a Knockout observableArray, or try the live fiddle.

    Be aware though that this binding depends on a fork of Knockout in order to work.

    Code

    Demo fiddle.

    HTML:

    <h1>Knockout Isotope Binding Demo</h1>
    <p>This is a demonstration of the 
     <a href="https://github.com/aknuds1/knockout-isotope">Knockout-Isotope</a>
     binding for <a href="http://knockoutjs.com/">Knockout</a>, which visualizes
     Knockout observableArrays through
     <a href="http://isotope.metafizzy.co/index.html">Isotope</a>.
    </p>
    
    <p>Click on an item to remove it or click in the item container to add a new item</p>
    <div id="container" data-bind="isotope: { data: items, isotopeOptions: getOptions }, click: addItem">
      <div data-bind="text: text, click: $parent.removeItem, clickBubble: false"></div>
    </div>
    

    JavaScript:

    function ItemModel(parent) {
        var value, self = this,
            found, i;
        for (value = 0; value < parent.items().length; ++value) {
            found = false;
            for (i in parent.items()) {
                var item = parent.items()[i];
                if (item.value() == value) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                break;
            }
        }
        this.value = ko.observable(value);
    
        this.text = ko.computed(function () {
            return "Item " + self.value();
        });
    }
    
    var ViewModel = function () {
        var self = this;
        self.items = ko.observableArray();
        self.items.push(new ItemModel(self));
        self.items.push(new ItemModel(self));
    
        this.removeItem = function (item) {
            self.items.remove(item);
        };
    
        this.addItem = function () {
            self.items.push(new ItemModel(self));
        };
    
        // Knockout callback for getting Isotope options
        this.getOptions = function () {
            return {
                masonry: {
                    columnWidth: 210
                }
            };
        };
    };
    
    ko.applyBindings(new ViewModel("Test"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a complex knockout.js object which is effectively an observableArray with another observableArray
Given an array mapped in knockout.js and using custom templates , how can one
I have a ko.observableArray and I've added a subscriber for items in the observable
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;
I'm working with a new application at work that we're building out using Knockout.js
I want to access the hidden field value in knockout. Here is my html
I use knockout-sortable.js to let the user drag and drop items to give them
Looking at this fiddle which uses knockout and backbone, are these libraries being automatically
I have a ViewModel that I created with knockout which contains all the info
I'm running into a problem with data* attributes in knockout.js ie. writing them out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.