Skip to content
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

Datatable sync #516

Merged
merged 11 commits into from May 13, 2017
Merged

Datatable sync #516

merged 11 commits into from May 13, 2017

Conversation

nekosaur
Copy link
Member

@nekosaur nekosaur commented May 10, 2017

Made the following changes:

This change allows for external control of pagination, sorting and selection.

Selected example (selectedKey defaults to 'id')

<v-data-table
  v-model="selected"
  :items="items"
  :headers="headers"
  select-all
  >
  <template slot="items" scope="props">
    <td><v-checkbox primary v-model="props.selected"></v-checkbox></td>
    <td>#{{ props.item.id }}</td>
    <td>{{ props.item.first_name }}</td>
    <td>{{ props.item.email }}</td>
    <td>{{ props.item.gender }}</td>
  </template>
</v-data-table>
...
<script>
  export default {
    data () {
      return {
        selected: []
      }
    }
  }
</script>

Pagination example (change default sort)

<v-data-table
  :pagination.sync="pagination"
  :items="items"
  :headers="headers"
  select-all
  >
  <template slot="items" scope="props">
    <td><v-checkbox primary v-model="props.selected"></v-checkbox></td>
    <td>#{{ props.item.id }}</td>
    <td>{{ props.item.first_name }}</td>
    <td>{{ props.item.email }}</td>
    <td>{{ props.item.gender }}</td>
  </template>
</v-data-table>
...
<script>
  export default {
    data () {
      return {
        pagination: {
          sortBy: 'first_name'
        }
      }
    }
  }
</script>

@nekosaur nekosaur added the T: enhancement Functionality that enhances existing features label May 10, 2017
desc: this.desc
})
isSelected (item) {
return this.selected && this.selected.find(i => i[this.selectedKey] === item[this.selectedKey])
},
sort (index) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this method could be cleaned up a bit. The same call is made for every scenario, the only thing that changes is the object that is emitted. Assign the value of that object and only have one this.$emit.

@@ -115,36 +105,51 @@ export default {
type: Boolean,
default: false
},
defaultSort: {
selected: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should let the selected be controlled under the model and the items be under a prop items, and just sync that. Would be curious to hear others thoughts.

v-model="yourSelectedRows"
:items.sync="tableItems"

this.sorting = this.defaultSort ? this.defaultSort.field : header.value
const firstSortable = this.headers.find(h => !('sortable' in h) || h.sortable)

let defaultPagination = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be const as it doesn't change value, could also just put it into the Object.assign arguments.

@avengerweb
Copy link
Contributor

Why default sort is part of pagination? Let's locate it in headers maybe?

@nekosaur
Copy link
Member Author

@avengerweb It's part of the synced prop so that sorting can be controlled outside of the data table. The end result is that it can also be used to set the default sorted column. Placing an option in the headers as well duplicates functionality which already exists.

@@ -3,7 +3,7 @@ import Body from './mixins/body'
import Foot from './mixins/foot'
import Progress from './mixins/progress'
import { getObjectValueByPath } from '../../util/helpers'

import Vue from 'vue'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this guy for?

@johnleider johnleider added the pending review The issue is still pending disposition label May 12, 2017
@johnleider
Copy link
Member

All reviewers have until Sunday to provide feedback.

@lock
Copy link

lock bot commented Apr 16, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please direct any non-bug questions to our Discord

@lock lock bot locked as resolved and limited conversation to collaborators Apr 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending review The issue is still pending disposition T: enhancement Functionality that enhances existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants