s-yadav / angulargrid

Pinterest like responsive masonry grid system for angular
MIT License
277 stars 105 forks source link

Dynamic number of columns #12

Closed maruiz93 closed 8 years ago

maruiz93 commented 8 years ago

I'd like to have a directive attribute which I can bind with my controller in order to dinamically change the number of columns.

I've tried an approach by changing the attribute grid-width so that I can calculate the minimum width for a specific number of columns but I think that with your current code the attribute grid-width it's only read once, with controller's initialization.

Is there another way to do this?

s-yadav commented 8 years ago

Right now it is not there, but it do make sense, I will be adding that flexibility on the module.

For quick fix you can change following line

angularGridInstance[agId] = {
                            refresh: reflowGrids
                        };

//to

angularGridInstance[agId] = {
                            refresh: reflowGrids,
                            options : options
                        };

options will be having gridWidth and gutterSize

For getting angularGrid Instance in your controller you have to inject angularGridInstance factory, and define a angular-grid-id on the element, through which you can access your instance.

ex :

<ul angular-grid="pics" angular-grid-id="gallery" > ... </ul>

Than in controller you can say

angularGridInstance.gallery.options.gridWidth = '350';
angularGridInstance.gallery.refresh();

I will be working on proper solution soon.