JavaScript How to fix overlapping bricks with Angular + Masonry?

I'm using passy's angular-masonry directives to render tiled elements in my app. Unlike a lot of the masonry examples, my bricks don't include images, just static text and layout content rendered through a custom directive. My setup looks like:

<div data-masonry
     data-column-width="250"
     data-load-images="false"
     data-preserve-order
     data-reload-on-show
     data-masonry-options="{ gutter: 15, isFitWidth: true, transitionDuration: 0 }">

     <div class="masonry-brick"
          data-ng-repeat="event in vm.events | orderBy: 'startTime.toDate()' | filter: (vm.showOnlyRegistered && { going: true })">

          <div data-event-item="event"></div>

     </div>
</div>

data-event-item is my directive that renders something like:

<div class="panel panel-default panel-thin light-shadow bgcolor-override event-item-card">
<div class="panel-body" data-ng-class="{'bg-success': event.going}">
    <div>
        <p class="text-medium text-thin">{{event.name}}</p>
    </div>

    <p>
        <strong>{{event.computed.locationName}}</strong><br />
        <span data-ng-if="!event.virtual">{{event.city}}, {{event.state}} {{event.zipCode}}</span>
    </p>
    <span class="center-block">
        <span data-discover-pill data-type="default">
            <span class="text-thin">{{event.computed.registrationLabel}}</span>
        </span>
    </span>

    <button type="button" 
            class="btn push-to-bottom bottom-center"
            data-ng-class="{'btn-default': !event.going, 'btn-success': event.going}"
            data-ng-click="toggleGoing(event.id)">
        I'm Going <i class="fa fa-check"></i>
    </button>
</div>

In my CSS, I have a defined width and height for the elements that go into the bricks, so that (plus the fact that I'm explicitly setting masonry column-width) should let masonry know how big all my bricks are.

Everything works fine except that sometimes (randomly?) on pageload all the bricks are rendered stacked on top of one another in a big pile on the left edge, as if the layout routine didn't trigger. If the window is manually resized, everything snaps to normal and stays that way. This seems to be a problem that some others have run into: https://github.com/passy/angular-masonry/issues/82

I've tried all the combinations of preserve-order and load-images="false" and so on. I think I need to manually trigger a reload/relayout, but as far as I know with the passy directive, you can't directly call masonry methods.

Answer:1

I kept running into issues with Passy's directive. Perhaps it was due to the number of bricks I was loading or my styling but I kept getting a lot of sporadic overlaps, delayed reloading of bricks and so on.

I switched to klederson's angular-masonry-directive and have been extremely happy with the decision. I haven't benchmarked to confirm but it seemed to have sped up load times.

angular-masonry-directive

A very simple and 100% compatible masonry directive for AngularJS ... do you know how to use masonry? Good! You know how to use this.

This directive is meant for the raw masonry lib and not the jQuery one.

Answer:2

For anyone running into a similar problem, I figured it out with some help from these answers. As a bonus, this helps me with refreshing after using Angular filters to modify which bricks are shown (the second linked answer deals with this).

Here's my working code, which I trigger when my async data has loaded on pageload, and also anytime the data is filtered or resorted:

function refresh() {
    // We need to give Masonry a little jump-start, otherwise the bricks
    // will render in one big overlapped stack sometimes
    common.$timeout(function () { $scope.$broadcast('masonry.reload'); }, 100);
}

Without $timeout, it looks (to my poorly-trained eyes) like the reload message is being consumed before the digest cycle completes, so the filtering or sorting may not have already taken place. I'm not sure that this is the best solution, but it seems to work in my testing so far. If anyone has a better one, I'd love to see it.

Answer:3

Im using datatables and I came across for a self requirements where I want a live table data and I use datatables for this requirements, however Im having an issue when displaying the pulled data from ...

Im using datatables and I came across for a self requirements where I want a live table data and I use datatables for this requirements, however Im having an issue when displaying the pulled data from ...

  1. datatables live records add edit delete

Ok, so I need to trigger an event when specific (let's say number 2) slide is displayed. I've checked this function: $('#myCarousel').bind('slide.bs.carousel', function (e) { console.log($(this));...

Ok, so I need to trigger an event when specific (let's say number 2) slide is displayed. I've checked this function: $('#myCarousel').bind('slide.bs.carousel', function (e) { console.log($(this));...

  1. trigger specific event vba
  2. c# trigger event specific time
  3. trigger event at specific time
  4. jquery trigger specific event
  5. javascript trigger event at specific time
  6. java trigger event at specific time
  7. android trigger event at specific time
  8. specific trigger event

I have this: <fieldset id="booom"> <label><INPUT TYPE="checkbox" NAME="a" VALUE="a">something></label> <label><INPUT TYPE="checkbox" NAME="b" VALUE="b">...

I have this: <fieldset id="booom"> <label><INPUT TYPE="checkbox" NAME="a" VALUE="a">something></label> <label><INPUT TYPE="checkbox" NAME="b" VALUE="b">...

  1. check checkboxes checked jquery
  2. check checkbox checked
  3. check checkbox checked or not in jquery
  4. check checkbox checked javascript
  5. check checkbox checked or not
  6. check checkbox checked js
  7. check checkbox checked or not in javascript
  8. check checkbox checked or not using jquery
  9. check checkbox checked php
  10. check checkbox checked or unchecked using jquery
  11. check checkbox checked in angularjs
  12. check checkbox checked or not in php
  13. check checkbox checked c#
  14. check checkbox checked angular
  15. check checkbox checked true in jquery
  16. check checkbox checked value jquery
  17. check checkbox checked android
  18. check checkbox checked property using jquery
  19. check checkbox checked or not in js
  20. check checkbox checked using jquery

Here is what i'm getting from json file /Date(1435837792000+0000)/ I need to display date in the following format Oct 29, 2010 9:10:23 AM

Here is what i'm getting from json file /Date(1435837792000+0000)/ I need to display date in the following format Oct 29, 2010 9:10:23 AM

  1. parse date field in excel
  2. parsing field date
  3. json parse date field
  4. java parse date field
  5. failed to parse date field
  6. failed to parse date field with format epoch_millis
  7. failed to parse date field elasticsearch
  8. failed to parse date field with format
  9. failed to parse date field with format epoch_second
  10. failed to parse date field kibana
  11. failed to parse date field with format dateoptionaltime
  12. failed to parse date field with format elasticsearch
  13. failed to parse date field with format yyyy-mm-dd
  14. failed to parse date field elastic
  15. elasticsearchparseexception failed to parse date field
  16. discover failed to parse date field
  17. logstash failed to parse date field
  18. elastalert failed to parse date field
  19. kibana failed to parse date field with format
  20. mapperparsingexception failed to parse date field