docs/app/pages/Components/Table/examples/TableSingle.vue
<template>
<div>
<md-table v-model="people" md-card @md-selected="onSelect">
<md-table-toolbar>
<h1 class="md-title">Selection Colors</h1>
</md-table-toolbar>
<md-table-row slot="md-table-row" slot-scope="{ item }" :class="getClass(item)" md-selectable="single">
<md-table-cell md-label="ID" md-sort-by="id" md-numeric>{{ item.id }}</md-table-cell>
<md-table-cell md-label="Name" md-sort-by="name">{{ item.name }}</md-table-cell>
<md-table-cell md-label="Email" md-sort-by="email">{{ item.email }}</md-table-cell>
<md-table-cell md-label="Gender" md-sort-by="gender">{{ item.gender }}</md-table-cell>
<md-table-cell md-label="Job Title" md-sort-by="title">{{ item.title }}</md-table-cell>
</md-table-row>
</md-table>
<p>Selected:</p>
{{ selected }}
</div>
</template>
<script>
export default {
name: 'TableSingle',
data: () => ({
selected: {},
people: [
{
id: 1,
name: 'Shawna Dubbin',
email: 'sdubbin0@geocities.com',
gender: 'Male',
title: 'Assistant Media Planner'
},
{
id: 2,
name: 'Odette Demageard',
email: 'odemageard1@spotify.com',
gender: 'Female',
title: 'Account Coordinator'
},
{
id: 3,
name: 'Lonnie Izkovitz',
email: 'lizkovitz3@youtu.be',
gender: 'Female',
title: 'Operator'
},
{
id: 4,
name: 'Thatcher Stave',
email: 'tstave4@reference.com',
gender: 'Male',
title: 'Software Test Engineer III'
},
{
id: 5,
name: 'Clarinda Marieton',
email: 'cmarietonh@theatlantic.com',
gender: 'Female',
title: 'Paralegal'
}
]
}),
methods: {
getClass: ({ id }) => ({
'md-primary': id === 2,
'md-accent': id === 3
}),
onSelect (item) {
this.selected = item
}
}
}
</script>
<style lang="scss" scoped>
.md-table + .md-table {
margin-top: 16px
}
</style>