【问题标题】:Unselect first row search in ng2-smart-table在 ng2-smart-table 中取消选择第一行搜索
【发布时间】:2022-03-17 07:40:32
【问题描述】:

有什么方法可以取消选择ng2-smart-table 中的第一行吗?请注意,一旦它被加载,第一行总是有 selected 类。问题是我想在.scss 文件中添加一个hover 来更改背景,但它永远不会更改第一个,但所有的reaming 行都可以更改背景。

tbody {
    tr:hover {
        background: #209e91;
    }
}

this例子,第一行加载的时候有背景。

编辑:

查看源似乎是任意选择:

data-set.ts

protected willSelect: string = 'first';
  ...
  select(): Row {
    if (this.getRows().length === 0) {
      return;
    }
    if (this.willSelect) {
      if (this.willSelect === 'first') {
        this.selectFirstRow();
      }
      if (this.willSelect === 'last') {
        this.selectLastRow();
      }
      this.willSelect = '';
    } else {
      this.selectFirstRow();
    }

    return this.selectedRow;
  }

【问题讨论】:

    标签: css angular sass hover


    【解决方案1】:

    添加 !important 以覆盖 selected 类的样式

    tbody tr:hover {
        background: #209e91 !important;
    }
    

    【讨论】:

      【解决方案2】:

      只需像这样将 selectedRowIndex: -1 添加到您的表格设置中

      tableSettings = { 
        hideSubHeader: true, 
        mode: 'external', 
        selectedRowIndex: -1
      };
      

      来源:https://github.com/akveo/ng2-smart-table/issues/502#issuecomment-876178945

      这会阻止默认选择第一行。

      【讨论】:

      • 我知道这是一个老问题,但今天遇到同样的问题让我搜索并发现这是“真正的”解决方案。
      猜你喜欢
      • 2019-01-08
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2020-07-08
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多