Coder Social home page Coder Social logo

Comments (3)

chrisgco avatar chrisgco commented on June 5, 2024

+1

from angular-deckgrid.

symrad avatar symrad commented on June 5, 2024

This is the solution I implemented (I know it can be done in a more elegant way, with regard to $$addElementsToColumns function but unfortunately I did not have much time):

Deckgrid.prototype.$$onModelChange = function $$onModelChange (newModel, oldModel) {
            var self = this;
            newModel = newModel || [];
            oldModel = oldModel || [];

            var newModelOldLength = angular.copy(newModel);
            newModelOldLength.splice(oldModel.length);

            if(angular.equals(oldModel, newModelOldLength) && oldModel.length != 0){
                var elementsToAdd = angular.copy(newModel);
                elementsToAdd = elementsToAdd.splice(-(newModel.length - oldModel.length));
                self.$$addElementsToColumns(elementsToAdd);
            }else{
                self.$$createColumns();
            }
};

Deckgrid.prototype.$$addElementsToColumns = function $$addElementsToColumns (elements) {
            var self = this;

            if (!this.$$scope.layout) {
                return $log.error('angular-deckgrid: No CSS configuration found (see ' +
                                   'https://github.com/akoenig/angular-deckgrid#the-grid-configuration)');
            }

            angular.forEach(elements, function onIteration (card, index) {
                index = self.$$getTotalElements();
                var column = (index % self.$$scope.layout.columns) | 0;

                if (!self.$$scope.columns[column]) {
                    self.$$scope.columns[column] = [];
                }

                card.$index = index;
                self.$$scope.columns[column].push(card);
            });
};

Deckgrid.prototype.$$getTotalElements = function $$getTotalElements () {
        var number = 0;
        angular.forEach(this.$$scope.columns, function onIteration (value, index) {
                number += value.length;
        });
            return number;
};

This is my fork https://github.com/symrad/angular-deckgrid/blob/master/angular-deckgrid.js.

from angular-deckgrid.

Tsarpf avatar Tsarpf commented on June 5, 2024

@symrad Thanks, your changes work great!

from angular-deckgrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.