vaadin-与CSS打印网格
vaadin-grid.css 我设法获得了包含网格行的#table
元素“>
,例如,
#table th {
backround-color:green;
}
我可以更改其颜色。
现在,我只需要在打印页面时才做
@media print {
#table th {
backround-color:green;
}
}
。打印()。 我在封闭的网格中添加了一个 id =“ viewfgrid” (如屏幕截图所示) 内部共享风格
@media print {
#viewfgrid {
outline:green;
}
}
我可以在打印时访问和更改网格。
但是,我无法使用行访问内表。我尝试了各种变体,例如
@media print {
#viewfgrid #table {
background-color:green;
}
}
@media print {
#viewfgrid :host > table {
background-color:green;
}
}
但没有效果。
如何访问该桌子?
另外,作为次要问题,为什么我可以在vaadin-grid.css中访问#table而不准备:主机?当我这样做时,它没有
效果
Inside vaadin-grid.css I managed to get the #table element which contains the grid's rows
and with for example
#table th {
backround-color:green;
}
I can change its color.
Now I need to do that only when the page is printed.I tried adding inside vaadin-grid.css
@media print {
#table th {
backround-color:green;
}
}
but that has no effect.Note that I print the page using javascript print().
I added an id="viewfgrid" (as seen in the screenshot) to the enclosing grid and with that now when I add
inside shared-style.css
@media print {
#viewfgrid {
outline:green;
}
}
I can access and change the grid when printing.
However I can't access the inside table with the rows.I tried various variations like
@media print {
#viewfgrid #table {
background-color:green;
}
}
@media print {
#viewfgrid :host > table {
background-color:green;
}
}
but no effect.
How can I access that table ?
Also as a secondary question why can I access #table from within vaadin-grid.css without prepending :host ? when I do that , it has no effect
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定为什么
@Media Print
在网格的阴影DOM样式中无法使用。您是否尝试过不同的浏览器?我想知道这里是否有一些浏览器错误/限制,类似于您无法在Shadow dom内定义@font-face
。主机选择器的目标是与
#viewfgrid
ID相同的元素。要选择具有特定ID的主机元素,您可以在阴影DOM样式内使用:host(#viewfgrid)
。请注意,在造型Vaadin组件时,您不应依靠任何ID,类名称或原始标签名称选择器(例如
#Table
或th
。这些被视为内部实现详细信息/私有API,可以在任何版本中更改。选择器和状态属性选择器(用于示例,[focused]
)。 ” https://developer.mozilla.org/en-us/docs/web/css/:: part“ rel =” nofollow noreferrer“>
:: part()
选择器,它允许您从外部/轻/dom样式中样式的命名零件。这实际上是一种比依赖更强大的方法 注入阴影DOM(通过frontend/mytheme/components/vaadin-grid.css
文件将样式
)文档显示网格的所有可用部分(查找“样式”部分): https://cdn.vaadin.com/vaadin-web-components/23.2.0-alpha3/#/elements/vaadin-grid
I’m not sure why
@media print
would not work from within the Grid’s shadow DOM styles. Did you try in different browsers? I wonder if there’s some browser bug/limitation here, similar to the fact that you can’t define a@font-face
inside shadow DOM.The host selector targets the same element as the
#viewfgrid
ID. To select a host element with a specific ID, you can use:host(#viewfgrid)
inside the shadow DOM styles.Notice, that you should not rely on any ID, class name, or raw tag name selectors when styling Vaadin components (for example
#table
orth
. Those are considered internal implementation details / private API, and can change in any release. You should only rely on the:host(...)
and[part~="..."]
selectors and state attribute selectors (for example,[focused]
).If there really is a limitation in using
@media print
inside shadow DOM styles, I think your best option is to use the::part()
selector, which allow you to style named parts inside the shadow DOM from the outside/light DOM styles. That is actually a more robust method than relying on injecting styles into the shadow DOM (via thefrontend/mytheme/components/vaadin-grid.css
file).styles.css:
The API docs show all available parts of the Grid (look for the "Styling" section): https://cdn.vaadin.com/vaadin-web-components/23.2.0-alpha3/#/elements/vaadin-grid
网格是设计不太印刷友好的,因为它是为“无限垂直滚动”设计的。例如,您不会每个页面都有标题和页脚。如果要将“报告”功能包含在应用程序中,则最好的方法是创建设计的单独的报告视图而不是屏幕使用。这将使您可以在其中使用不同的布局和组件。例如,您可以为每个页面生成多个网格。或使用 beantable 目录中的组件,这些组件来自目录,它们会生成无阴影dom的html表。
Grid is by design not very printing friendly as it has been designed for "infinite vertical scrolling". You wont for example have headers and footers per page. If you want to include "report" functionality to your application, it is better approach to create separate report view that is designed printing friendly instead of screen use. This will allow you to use different layouting and components in it. You can for example generate multiple Grid's for each page. Or use BeanTable component from Directory, which generaters HTML Table without shadow DOM.
因为显然,当元素上没有“零件”标签时,您无法从CSS访问Shadow dom,就像此 table 一样,我通过使用JavaScript(如
:当用户单击打印按钮时,可以使用摘要来调用摘要,您可以使用元素的样式进行操作。在我的情况下,我将桌子弄平,以便可以在不介入的情况下打印它。
Because apparently you can't access the shadow dom from CSS when there's no 'part' tag on the element,as is the case with this table,I got it by using Javascript as in :
So now this snippet is called when the user clicks on a Print button and you can do whatever with the element's style.In my case I flatten the table so that it can be printed without the scrollbar intervening.