Skip to content

Add row click event #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ rows => Rows. => [
]
perPage => Number of rows per.. page => 10 (default) // Results per page
onClick => Func. to execute on click => console.log // Function, row 1st param
clickable => Rows are clickable. => true (default) //row is passed in the event payload
Will fire `row-click` event //see react to click on row (below)
sortable => Cause column-click to sort => true (default) // Whether sortable
searchable => Add fuzzy search functionality => true (default) // Whether searchable
exactSearch => Disable fuzzy search => true (default) // Whether only exact matches are returned
Expand All @@ -101,3 +103,28 @@ customButtons => Custom buttons thingy => [
}
]
```

### React to click on row

The datatable will emit the `row-click` event if `clickable` is set to `true` (default).

The events payload will contain the `row object`, you can bind to the event like this:

```html
<datatable v-on:row-click="onRowClick"></datatable>

<script>
var app = new Vue({
el: '#app',
...
methods: {
onRowClick: function (row) {
//row contains the clicked object from `rows`
console.log(row)
  }
},
})
</script>
...

```
13 changes: 8 additions & 5 deletions src/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</thead>

<tbody>
<tr v-for="(row, index) in paginated" :class="onClick ? 'clickable' : ''" @click="click(row, index)">
<tr v-for="(row, index) in paginated" :class="{ clickable : clickable }" @click="click(row)">
<td v-for="column in columns" :class="column.numeric ? 'numeric' : ''" v-if="!column.html">
{{ collect(row, column.field) }}
</td>
Expand Down Expand Up @@ -111,7 +111,7 @@
title: '',
columns: {},
rows: {},
onClick: {},
clickable: {default: true},
customButtons: {default: () => []},
perPage: {default: 10},
sortable: {default: true},
Expand Down Expand Up @@ -164,9 +164,12 @@
this.searching = !this.searching;
},

click: function(row, index) {
if (this.onClick)
this.onClick(row, index);
click: function(row) {
if(!this.clickable){
return
}

this.$emit('row-click', row)
},

exportExcel: function() {
Expand Down