ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Bootstrap Dropdown in header template

Open gabiufrj opened this issue 11 years ago • 19 comments

Hello! I've been using the ui-grid 3.0 recently, and so far, it's been pretty great! Nice work there!

But I want to customize my header cells, so I can put more information there. I managed to create a custom header cell template as indicated in the docs. The only problem is that I've been trying to use bootstrap dropdowns in the column headers and it appears to be lying "behind" the grid.

As indicated in the repo, I've created a StackOverflow question first, with the appropriated tags (http://stackoverflow.com/questions/28864376/ng-grid-3-0-bootstrap-dropdown-in-column-header). The only comment I got kind of helps me, but isn't the optimal solution. I was wondering if you guys have encountered that problem already and know how I can overcome this. From some googling, I think it has something to do with overflow properties, but I couldn't manage to make it work.

This plunkr (http://plnkr.co/edit/qdrFiifiz18fxB8w6Aja?p=preview) shows the issue.

Thanks in advance!

gabiufrj avatar Mar 06 '15 15:03 gabiufrj

Bootstrap in general is something we don't do well at present. I have in mind a bootstrap feature, which would provide styles etc to play nice with bootstrap (and perhaps include bootstrap editors for the edit feature). But it's just an idea at the moment: #2586 #2290

PaulL1 avatar Mar 10 '15 07:03 PaulL1

OK, looking further, there is an overflow property in three places:

  • ui-grid-top-panel
  • ui-grid-header-viewport
  • ui-grid-cell-contents

If you replace all them with overflow: visible in the chrome element editor, then it shows.

I'm not all that good at css, but I suspect there's a way to override them individually in your css file. I tried doing it the obvious way (creating .ui-grid-top-panel { overflow: visible; } etc), and that didn't take effect. So there must be something trickier needed.

PaulL1 avatar Mar 10 '15 08:03 PaulL1

Ok, thank you for the answer! I'll look more into it and keep in mind that I might not be able to use bootstrap menus =)

gabiufrj avatar Mar 10 '15 14:03 gabiufrj

If anyone is interested, thanks to the tips from Paul, I managed to create a working plunkr with the bootstrap dropdown, the only difference is the CSS file.

http://plnkr.co/edit/qdrFiifiz18fxB8w6Aja?p=preview

gabiufrj avatar Mar 10 '15 14:03 gabiufrj

I Used this tip in my grid 1 month ago, but this tip doesn't work when you add to many columns in the grid. The horizontal scroll bar will appear, and when you'll scroll to the right, the headers won't move according to the ui-grid-viewport.

I tried to let the overflow:hidden and use the position:absolute property on my dropdown to break it out of the parent ui-grid-header-viewport. But it sill not works as the ui-grid-header-cell need to be in position:relative (the dropdown absolute position refers to the first relative parent to compute its state).

The only way I managed to make it working is to mimic the behaviour of the column menu dropdown. It is added to an empty container, out of any ui-grid-header/ui-grid-viewport, appended to the main grid container, and computing the absolute position of the dropdown using javascript.

sbrouil avatar Mar 25 '15 16:03 sbrouil

I also have a dropdown/tooltip in my header cell template. Whenever I comment out overflow: hidden; or make it overflow: visible; the x-scrolling of the ui-grid header breaks. Is there a way to get the scrolling to work while also having a tooltip in the header?

jercoh avatar Apr 22 '15 22:04 jercoh

You shouldn't modify the overflow property. I used another workaround :

  • put your dropdown in position: fixed. Your dropdown will 'float' over the grid
  • on scroll, close the dropdown, or replace it according to column position otherwise the dropdown won't be aligned with the column.

sbrouil avatar Apr 23 '15 07:04 sbrouil

Yes of course, this solution works but, toggling the overflow property shouldn't have any effect on the horizontal scrolling.

jercoh avatar Apr 23 '15 15:04 jercoh

An easy fix for this problem is to override the uiGridMenu template and use the built-in column menu.

jercoh avatar Apr 24 '15 15:04 jercoh

Hey guys, Thanks for the info above. I'm a bit stuck on this same issue. I've tried all of the approaches and I'm working on the one that @sylvain-brouillat suggested. Is the columns horizontal position relative to the screen accessible through ui grid? How did you get at that value?

spencerhandley avatar Jun 10 '15 04:06 spencerhandley

Also having this issue overwriting the overflow values to

overflow: visible

and the headers break when scrolling horizontally

yeemighty avatar Aug 20 '15 21:08 yeemighty

I am proud to say I think I've figured it out. I've been digging through ui-grid's source code and narrowed it down to this block (lines: 2847 - 2852).

function syncHorizontalHeader(scrollEvent){
    var newScrollLeft = scrollEvent.getNewScrollLeft(colContainer, containerCtrl.viewport);
    if (containerCtrl.headerViewport) {
        containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);
    }
}

I noticed that containerCtrl.headerViewport.scrollLeft was never getting set to newScrollLeft. A quick google search led me to this StackOverflow thread which says that you can't set the scrollLeft property of an element if it's overflow is set to visible.

My solution was to replace containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid); with containerCtrl.headerViewport.style.marginLeft = -gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid) + 'px'; which just sets a negative margin on the header. Then add an overflow:hidden; style to .ui-grid-render-container-body to hide headers that extend beyond the main grid viewport.

Doing this messed up the placement of column menus, but there is an easy fix. On line 514 replace var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft; with var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].style.marginLeft; to use the margin instead of the scroll value in the menu placement calculation.

anticommander avatar Nov 20 '15 15:11 anticommander

@gabiufrj Thanks, that worked for me!

.ui-grid-top-panel {
  overflow: visible;
}

.ui-grid-header-viewport {
  overflow: visible;
}

.ui-grid-cell > .ui-grid-cell-contents {
  overflow: visible;
}

hboylan avatar Dec 15 '15 18:12 hboylan

Just kidding, like everyone else says, this solution breaks once the grid becomes wide enough to need horizontal scroll

hboylan avatar Dec 16 '15 15:12 hboylan

@hboylan

I've outlined a solution for the horizontal scrolling issues in a comment above.

First, on line 2850 replace:

containerCtrl.headerViewport.scrollLeft = gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid);

with

ontainerCtrl.headerViewport.style.marginLeft = -gridUtil.denormalizeScrollLeft(containerCtrl.viewport,newScrollLeft, grid) + 'px';

This will handle moving the columns when you scroll horizontally.

Second, add overflow:hidden; to the .ui-grid-render-container-body style. This will hide any overhang from headers that extend beyond the main grid container.

Finally, on line 514 replace:

var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft;

with

var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].style.marginLeft;

This will handle positioning column menus when the grid has been scrolled horizontally.

anticommander avatar Dec 16 '15 15:12 anticommander

Same issue for me trying to open a help popover by clicking an icon next to a column name. While the workarounds above do help, it would be nice if this fix could be added to ui-grid.

richardm avatar Oct 21 '16 21:10 richardm

@hboylan

Still i have issue if i increase the height of dropdown...

rafiqueshaikh avatar Jan 25 '17 09:01 rafiqueshaikh

I am also stuck with same issue. I couldn't change ui-grid's source code file. Since it will affect other templates in SPA. Please anyone give some more solution for this issue.

Jeeva772 avatar Jun 02 '17 12:06 Jeeva772

The plunker in question does not appear to have the issue anymore. Closing it. http://plnkr.co/edit/APG0zMTsNKrMYKOroZve?p=preview

mportuga avatar Jan 20 '18 18:01 mportuga