iview,table组件怎么用代码设置当前选中行

iview,table组件怎么用代码设置当前选中行

阅读 9.7k
4 个回答

1.鼠标点击选中
Table props:
highlight-row 是否支持高亮选中的行,即单选 Boolean false;

<Table highlight-row :columns="columns" :data="data1"></Table>

2.指定某行,或多行显示
Table props:
row-class-name 行的 className 的回调方法,传入参数:row:当前行数据index:当前行的索引 Function -

<Table :row-class-name="rowClassName" :columns="columns" :data="data"></Table>
methods: {
    rowClassName (row, index) {
        if (index === 1) {
            return 'demo-table-info-row'; // 样式名
        } else if (index === 3) {
            return 'demo-table-error-row'; // 样式名
        }
        return '';
    }
}

//这是手动设置选中的行。this.$refs.mytable指的是ivew的table表格
this.$refs.mytable.$refs.tbody.clickCurrentRow(0)

不要用他默认table的selection,自己生成复选框,自己做选中,iview自己的多选有点鸡肋

新手上路,请多包涵

如果是多选的话,可以用 table 组件里的 toggleSelect 方法

this.$refs.mytable.$refs.table && this.$refs.mytable.$refs.table.toggleSelect(index)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进