效果图javascript
<Table ref="selection" @on-selection-change="onSelect" height="700" no-data-text="暂无数据" :row-class-name="rowClassName" :columns="columns4" :data="data1" highlight-row></Table>
/*底色*/ .ivu-table td{ background-color: #182328; color: #fff; }
/*头部th*/ .ivu-table-header th{ color:#FFD3B4; font-weight: bold; background-color: #212c31; border: none; }
那就简单了,上面Table标签的:row-class-name="rowClassName"
就是在这个地方用,定义样式css
/*偶数行*/ .ivu-table-stripe-even td{ background-color: #434343!important; } /*奇数行*/ .ivu-table-stripe-odd td{ background-color: #282828!important; }
接下来定义rowClassName方法html
rowClassName :function (row, index) { if(index%2==0){ return 'ivu-table-stripe-even'; } else return 'ivu-table-stripe-odd'; }
一顿操做以后:前端
/*浮在某行*/ .ivu-table-row-hover td { background-color: #d63333!important; }
highlight-row
就是选中高亮,不起做用的缘由是被覆盖掉了,那就在写一个样式/*选中某一行高亮*/ .ivu-table-row-highlight td { background-color: #d63333!important; }
@on-selection-change="onSelect" @on-selection-change标签有两个参数,selection已选项,index当前索引
onSelect(selection,index){ // console.log(this.$refs.selection.data) this.selecteds = selection; console.log(this.selecteds) }
_checked: true
{ apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03', _checked: true }
<style> /*外层table的border*/ .ivu-table-wrapper { border:none } /*底色*/ .ivu-table td{ background-color: #182328; color: #fff; } /*每行的基本样式*/ .ivu-table-row td { color: #fff; border:none } /*头部th*/ .ivu-table-header th{ color:#FFD3B4; font-weight: bold; background-color: #212c31; border: none; } /*偶数行*/ .ivu-table-stripe-even td{ background-color: #434343!important; } /*奇数行*/ .ivu-table-stripe-odd td{ background-color: #282828!important; } /*选中某一行高亮*/ .ivu-table-row-highlight td { background-color: #d63333!important; } /*浮在某行*/ .ivu-table-row-hover td { background-color: #d63333!important; } </style> <template> <div> <Table ref="selection" @on-selection-change="onSelect" height="700" no-data-text="暂无数据" :row-class-name="rowClassName" :columns="columns4" :data="data1" highlight-row></Table> <Button @click="handleSelectAll(true)">Set all selected</Button> <Button @click="handleSelectAll(false)">Cancel all selected</Button> </div> </template> <script> export default { data () { return { selecteds: [], columns4: [ { type: 'selection', width: 60, align: 'center' }, { title: '苹果', key: 'apple' }, { title: '香蕉', key: 'banana' }, { title: '橘子', key: 'orange' }, { title: '西瓜', key: 'watermelon' }, { title: '牛奶', key: 'milk' }, { title: '面包', key: 'Bread' }, { title: '盐', key: 'salt' }, { title: '小麦', key: 'wheat' }, { title: '大米', key: 'rice' }, { title: '酱油', key: 'soy' }, { title: '其余', key: 'else' } ], data1: [ { apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03' },{ apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03' },{ apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03' },{ apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03', _checked: true },{ apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03' },{ apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03' },{ apple: 'John Brown', banana: '18', orange: 18, watermelon: 'New York No. 1 Lake Park', milk: '2016-10-03', Bread: 'New York No. 1 Lake Park', salt: '2016-10-03', wheat: 'New York No. 1 Lake Park', rice: '2016-10-03', soy: 'New York No. 1 Lake Park', else: '2016-10-03' } ] } }, methods: { handleSelectAll (status) { // this.$refs.selection.selectAll(status); // console.log(this.$refs.selection.$children) this.$refs.selection.selectAll(status); console.log(this.selection) }, rowClassName :function (row, index) { if(index%2==0){ return 'ivu-table-stripe-even'; } else return 'ivu-table-stripe-odd'; }, onSelect(selection,index){ // console.log(this.$refs.selection.data) this.selecteds = selection; console.log(this.selecteds) } /*, onDoubleClick(row,index){ console.log(row) //改变为勾选样式 //将当前行加入到selection this.$refs.selection.data[index]._checked=!this.$refs.selection.data[index]._checked }*/ } } </script>