gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

Show grid lines

Open ronvanpol opened this issue 8 years ago • 15 comments

Does anyone have any idea of how to add grid lines to a gridstack? When working with bigger gridstacks, it helps a lot to place an item on the gridstack if grid lines could be shown (for instance like Excel)

ronvanpol avatar May 11 '17 08:05 ronvanpol

Good question, @ronvanpol . You'll want to do this with CSS. Maybe someone better than I am at CSS will be able to offer you some assistance. If not, I'll spend some time looking into it when I have a chance. Thanks for using gridstack! You may want to check out the gridstack Slack to get a wider audience's attention as well

radiolips avatar May 12 '17 13:05 radiolips

Hi @radiolips. Is there any update on showing grid lines lets say if a grid is initialized for 12 col and 12 rows to begin with?

sohaib-khan avatar May 26 '17 14:05 sohaib-khan

Hey @sohaib-khan . We haven't had a chance to look into that just yet. We're hard at work with some bugs and major 1.0 features. When I have a chance to look into these grid lines, I'll update this ticket. Thanks for the ping. I'd love to one day make gridstack.js a full-time job, but for the time being, I'm devoting as much time as I can :).

radiolips avatar May 28 '17 16:05 radiolips

@radiolips great! I will be following when this new feature kicks in. It will be a good visual cue for snapping divs to the grid.

sohaib-khan avatar May 29 '17 12:05 sohaib-khan

Hi we can try following css workaround for now(try manipulating background-size based on ur requirement):

.grid-stack {
   /* background-color: #eeeeee; */
background-image: linear-gradient(#e0e0e0 1px, transparent 1px), linear-gradient(90deg, #e0e0e0 1px, transparent 0px), linear-gradient(rgba(255,255,255,.3) 5px, transparent 100px), linear-gradient(90deg, rgba(255,255,255,.3) 5px, transparent 100px);
background-size: 100px 62px, calc(8.33% + 0px) 100px, 20px 20px, 20px 20px;
background-position: -2px -2px, -1px -2px, -1px -1px, -1px -1px;}  

image

imPrashik avatar Mar 11 '18 11:03 imPrashik

is there a way to combine the solution mentioned above with usage of custom number of columns?

dfenerski avatar Jun 26 '20 13:06 dfenerski

Yes, the part where it says 'calc(8.33% + 0px)' replace it with 'calc(100/N% + 0px)' where N is your amount of columns

tomasrivero avatar Sep 28 '20 16:09 tomasrivero

@tomasrivero this seems good, but what about the case of custom number of rows

dfenerski avatar Oct 17 '20 12:10 dfenerski

@adumesny Any planes yet when you would implement this if you will ever implement it?

Justin99b avatar Apr 07 '21 13:04 Justin99b

@Justin99b I wasn't planning on (low on the todo list) unless someone wants to donate to make it happen

adumesny avatar Apr 07 '21 14:04 adumesny

Doesn't this css fit?

    background-color: #F7F7F7;
    background-size : $cell-size $cell-size;
    background-image:
        linear-gradient(to right, $border-color 1px, transparent 1px),
        linear-gradient(to bottom, $border-color 1px, transparent 1px);

liesahead avatar Jun 11 '21 09:06 liesahead

I have used @liesahead 's example and make it work for my scenario. I always have 40 cells width, but I have dynamic number of rows

background-color: grey;
background-size: calc(100%/40) calc(100%/var(--gs-current-row, 30));
background-image:
    linear-gradient(to right, #FFF 1px, transparent 1px),
    linear-gradient(to bottom, #fff 1px, transparent 1px);

I use javascript to get the attributte gs-current-row from the grid element and then set it as a CSS Custom Property in inline style, so the CSS can use it for calc

However, for dynamic grid that will expand and shrink between min and max rows, I can't find a way to detect when the grid size changes.

Edit: I can use MutationObserver to watch for changes on gs-current-row Would be nice with an event from Gridstack :-)

atlemagnussen avatar Mar 02 '24 10:03 atlemagnussen

hi everyone, i've been trying to adjust the grid line so it would look like this but havent found any solution (yet): Screenshot 2024-04-24 at 15 30 06

any suggestion is appreciated. thanks!

delvinwidjaja avatar Apr 24 '24 13:04 delvinwidjaja