Tuesday, February 23, 2016

Select All checkbox using Knockout JS


Normal SelectAll CheckBoxes using Knockout
  // Select All checkbox
    self.SelectedAllPermissions = ko.computed({
        read: function () {
            var item = ko.utils.arrayFirst(self.SecurityPagesListArray(), function (item) {
                return !item.SelectedPage();
            });
            return item == null;
        },
        write: function (value) {
            ko.utils.arrayForEach(self.SecurityPagesListArray(), function (permission) {
                permission.SelectedPage(value);
            });
        }
    });

--------------------------------------------------------------------------------


Select All Checkbox from One Array to Another


// Select All checkbox
    self.SelectedAllPermissions= ko.computed({
        read: function () {
            return self.selectedBooks().length === self.filterBooks().length;
        },
        write: function (value) {
            self.selectedBooks(value ? self.filterBooks().slice(0) : []);
        },
        owner: self
    });


   <input style="margin-left:10px;width:20px;height:20px;" class="pull-left" type="checkbox" data-bind="checked: SelectedAllPermissions" />

No comments:

Post a Comment