0

How to add dynamic coordinate grid for angular-gridster?

My example http://jsfiddle.net/qqzvjvfx/24/

<div ng-app="someApp" ng-controller="someCtrl">
    <div gridster="gridsterOpts">
        <ul>
            <li class="" gridster-item="block" ng-repeat="block in sorted_blocks">
                <div class="panel panel-default">
                    <div class="panel-heading">{{ block.title }}</div>
                    <div class="panel-content image-responsive" 
                         ng-style="{'background-image':'url(' + block.image + ')'}"></div>
                </div>
            </li>
        </ul>
    </div>
</div>

Angular Controller:

angular.module('someApp', ['gridster']).controller('someCtrl', function ($scope, $http) {
    $scope.gridsterOpts = 
    {
        resizable: {
            enabled: true
        },
        columns: 4,
        rows: 16,
        minRows: 4,
        margins: [0,0],
        floating: false
    };
    $scope.sorted_blocks = [{
        id: 1,
        sizeX: 1,
        sizeY: 1,
        image: 'http://i.imgur.com/NI1Xm16.jpg',
        title: 'title1',
        row: 1,
        col: 2
    }, {
        id: 2,
        sizeX: 2,
        sizeY: 1,
        image: 'http://i.imgur.com/x6qmeUY.jpg',
        title: 'title2',
        row: 0,
        col: 0
    }];
});

Css:

.panel {
    display: flex;
    flex-flow: column wrap;
    height: 100%;
}

.panel .panel-content {
    flex-grow: 1;
}

.image-responsive {
    background-size: contain;
    background-repeat: no-repeat;
}

The width of gridster`s field are fixed - 4 columns, the height are dynamic, from 4 to 16 rows. I need to add grid under blocks, like this.

1 Answer 1

1

I found this codepen by Jason Delia, plugging it into your gridster works.

You'd have to change the background color of course, but it should do what you need:

html {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: #434343;
  background-image: linear-gradient(#434343, #282828);
}

#content {
  background-color: transparent;
  background-image: linear-gradient(0deg,  transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent), 
                    linear-gradient(90deg, transparent 24%, rgba(255, 255, 255, .05) 25%, rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent);
  height: 100%;
  background-size: 50px 50px;
}
<div id="content"></div>

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.