简体   繁体   English

选中时更改GWT网格的行鼠标悬停颜色

[英]Change row mouseover color of the GWT Grid when selected

When a button is pressed, i change the background of a few rows in a Grid component, I've achieved it so far, but, when the user mouses over the selected row, it does not show the color that is set, how to change the color of the mouse over item to match the selected item color? 按下按钮时,我更改了Grid组件中几行的背景,到目前为止,我已经实现了,但是,当用户将鼠标悬停在所选行上时,它不会显示设置的颜色,以及如何显示更改鼠标悬停在项目上的颜色以匹配所选项目的颜色? Code here so far. 到目前为止,这里的代码。

for(int i=0;i<grid.getStore().getCount();i++){
    Element row = (Element) grid.getView().getRow(i);
    row.getStyle().setProperty("backgroundColor", "#FFFFFF");
}
for(int item:items){
    Element row = (Element) grid.getView().getRow(item);
    row.getStyle().setProperty("backgroundColor", "#DFE8F6");
}

Changed as per the answer. 根据答案更改。

for(int i=0;i<grid.getStore().getCount();i++){
    Element row = (Element) grid.getView().getRow(i);
    row.getStyle().setProperty("backgroundColor", "#FFFFFF");
    row.removeClassName("ps-grid-selected-row");                    
}
Element row = (Element) grid.getView().getRow(indexItem);
row.getStyle().setProperty("backgroundColor", "#DFE8F6");
//              row.getStyle().setProperty("hover", "#DFE8F6");
row.addClassName("ps-grid-selected-row");

The easiest way to add a mouse over color to the row is through CSS. 向行上的颜色添加鼠标的最简单方法是通过CSS。 In your CSS file, add an entry like this: 在您的CSS文件中,添加以下条目:

.selected-row:hover {
  background-color: #DFE8F6;
}

And back in your code, instead of setting the background color just add the CSS class: 然后返回您的代码,而不是设置背景颜色,只需添加CSS类:

for(int i=0;i<grid.getStore().getCount();i++){
  Element row = (Element) grid.getView().getRow(i);
  row.removeClassName( "selected-row" );
}
for(int item:items){
  Element row = (Element) grid.getView().getRow(item);
  row.addClassName( "selected-row" );
}

When you select the row, just add the selected-row classname and when it's not selected just remove the classname. 选择行时,只需添加selected-row类名,而未选择时只需删除该类名。 The CSS specifies that when the user hovers over the class selected-row , it will use the #DFE8F6 background color. CSS指定当用户将鼠标悬停在selected-row类上时,它将使用#DFE8F6背景色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM