A way to access the defaullt sorting method from Data Tables in Vuetify

sgf_1

I'm trying to add the default functionality for sorting information inside a Data table from Vuetify, but I couldn't make it appear.

Code Sandbox with some comments : https://codesandbox.io/s/vuetify-2-forked-wfhe9?file=/src/App.vue

<template>
  <v-app>
    <div>
      <v-data-table
        :headers="headers"
        :items="data"
        class="elevation-1 mt-4"
        :items-per-page="5"
        hide-default-header
      >
        <template v-slot:header="{ header }">
          <thead>
            <tr>
              <th
                v-for="(h, index) in headers"
                class="text-subtitle-2"
                style="border-bottom: 2px solid #bdc6d8"
                :key="index"
              >
                <v-tooltip bottom :key="h.value">
                  <template v-slot:activator="{ sort }">
                    <span v-on="sort">{{ h.text }}</span>
                  </template>
                </v-tooltip>
              </th>
            </tr>
          </thead>
        </template>
        <template #item="{ item }">
          <tr>
            <td style="border: 0; height: 70px">
              {{ item.name }}
            </td>
            <td style="border: 0; height: 70px">
              {{ item.date }}
            </td>
            <td style="border: 0; height: 70px">
              {{ item.quantity }}
            </td>
            <td style="border: 0; height: 70px">
              {{ item.expirationDate }}
            </td>
          </tr>
        </template>
      </v-data-table>
    </div>
  </v-app>
</template>

<script>
export default {
  data() {
    return {
      headers: [
        {
          text: "Name",
          align: "start",
          value: "name",
        },
        {
          text: "Date",
          align: "start",
          value: "date",
        },
        {
          text: "Quantity",
          align: "start",
          value: "quantity",
        },
        {
          text: "Expiration",
          align: "start",
          value: "expirationDate",
        },
      ],
      currentProds: [
        {
          name: "Proc 1",
          date: "01/01/01",
          quantity: 123,
          expirationDate: "01/02/02",
        },
        {
          name: "Proc 1",
          date: "01/01/01",
          quantity: 123,
          expirationDate: "01/02/02",
        },
        {
          name: "Proc 1",
          date: "01/01/01",
          quantity: 123,
          expirationDate: "01/02/02",
        },
        {
          name: "Proc 1",
          date: "01/01/01",
          quantity: 123,
          expirationDate: "01/02/02",
        },
        {
          name: "Proc 1",
          date: "01/01/01",
          quantity: 123,
          expirationDate: "01/02/02",
        },
      ],
    };
  },
};
</script>

<style>
</style>

Searching google I found code that apparently works but only in previous versions (i'm using the last one)

Why i'm doing the header again? Designer asked for a different border bottom so trying to do this I made the thead again using the slot.

I dont want to add a custom sort, just the default one.

Is there a way to do this in 2.4.3 verison of Vuetify?

Daniil Loban

I like this example from docs, also pay attention to dataSort function, for correct sorting implementation:

  const dataSort = ((a, b) =>  a.split('/').reverse().join('/') <=  b.split('/').reverse().join('/') ? -1: 1)


  new Vue({
    el: '#app',
    vuetify: new Vuetify(),
    data () {
      return {
        currentProds: [
          {
            name: "Proc 1",
            date: "07/01/01",
            quantity: 3,
            expirationDate: "07/02/02",
          },
          {
            name: "Proc 2",
            date: "02/01/01",
            quantity: 2,
            expirationDate: "02/02/03",
          },
          {
            name: "Proc 3",
            date: "01/01/01",
            quantity: 1,
            expirationDate: "01/02/01",
          },
          {
            name: "Proc 4",
            date: "01/01/01",
            quantity: 5,
            expirationDate: "01/02/02",
          },
          {
            name: "Proc 5",
            date: "01/01/01",
            quantity: 4,
            expirationDate: "01/02/02",
          },
        ],
      }
    },
    computed: {
      headers () {
        return [
          {
            text: 'Name',
            align: 'start',
            value: 'name',
          },
          {
            text: 'Date',
            value: 'date',
            sort: dataSort   // <----- important!
          },
          { 
            text: 'Quantity',
            value: 'quantity',
          },
          { 
            text: 'Expiration Date',
            value: 'expirationDate',
            sort: dataSort,  // <----- important!
          },
        ]
      },
    },
  })
<head>
  <meta charset="UTF-8">
  <title>CodePen - Vuetify Calendar Event Drag&#39;n&#39;Drop</title>
  <script src='https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js'></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
  <script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js'></script>
  <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900'>
  <link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css'>
  <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Material+Icons'>
  <link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css'>

<style>

.theme--light.v-data-table>.v-data-table__wrapper>table>tbody>tr:not(:last-child)>td:last-child,
.theme--light.v-data-table>.v-data-table__wrapper>table>tbody>tr:not(:last-child)>td:not(.v-data-table__mobile-row),
.theme--light.v-data-table>.v-data-table__wrapper>table>tbody>tr:not(:last-child)>th:last-child,
.theme--light.v-data-table>.v-data-table__wrapper>table>tbody>tr:not(:last-child)>th:not(.v-data-table__mobile-row),
.theme--light.v-data-table>.v-data-table__wrapper>table>thead>tr:last-child>th
{
    border-bottom: 0
}
.theme--light.v-data-table>.v-data-table__wrapper>table>thead>tr:last-child>th {
    border-bottom: 2px solid #bdc6d8;
}    
</style>
</head>
<body>
  <div id="app">
    <v-app id="inspire">
      <div>
        <v-data-table
          :headers="headers"
          :items="currentProds"
          item-key="name"
        >
        </v-data-table>
      </div>
    </v-app>
  </div>
</body>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

一种从Vuetify中的数据表访问defaullt排序方法的方法

来自分类Dev

How to use bootstrap css tables to display data from MySQL tables?

来自分类Dev

Nuxt - Cannot access data inside a method

来自分类Dev

Array index access from metatable field/method

来自分类Dev

Select data from three different tables with null data

来自分类Dev

Simplest way to return data from line in file

来自分类Dev

Copy data from multiple tables using insert into select

来自分类Dev

Temp Tables in MS Access

来自分类Dev

How do I access a jQuery plugin variable from within method?

来自分类Dev

selecting a column from ms-access database which has linked tables

来自分类Dev

制作像laravel defaullt这样的助手

来自分类Dev

Need "Method return type" of data selected with LINQ from DataTable

来自分类Dev

Angular delete obj data from array (issue with method)

来自分类Dev

How to make sorting through gridView method POST?

来自分类Dev

I am trying to select data from 2 mysql tables into 1 query

来自分类Dev

Purpose and usage of the optional parameter (additional) of the method data_for from the data_magic class

来自分类Dev

Is there any way to find out the tables relationship?

来自分类Dev

连接的data.tables副本

来自分类Dev

Event called when sorting data in kendo grid

来自分类Dev

Access to an Exception caught by the caller of a method

来自分类Dev

如何从Vuetify v-data-table获取过滤的数组?

来自分类Dev

如何在Vuetify v-data-table上对齐标题

来自分类Dev

Vuetify,为v-data-table tr动画

来自分类Dev

Vuetify:通过多个值搜索v-data-table?

来自分类Dev

如何清除v-data-table中的选定行,Vuetify

来自分类Dev

Select count from four tables

来自分类Dev

SELECT query from 2 tables

来自分类Dev

Angular js: Access data filtered in ng-repeat (ngRepeat) from controller

来自分类Dev

Retrieve data from SQL Server database using ajax method C#

Related 相关文章

  1. 1

    一种从Vuetify中的数据表访问defaullt排序方法的方法

  2. 2

    How to use bootstrap css tables to display data from MySQL tables?

  3. 3

    Nuxt - Cannot access data inside a method

  4. 4

    Array index access from metatable field/method

  5. 5

    Select data from three different tables with null data

  6. 6

    Simplest way to return data from line in file

  7. 7

    Copy data from multiple tables using insert into select

  8. 8

    Temp Tables in MS Access

  9. 9

    How do I access a jQuery plugin variable from within method?

  10. 10

    selecting a column from ms-access database which has linked tables

  11. 11

    制作像laravel defaullt这样的助手

  12. 12

    Need "Method return type" of data selected with LINQ from DataTable

  13. 13

    Angular delete obj data from array (issue with method)

  14. 14

    How to make sorting through gridView method POST?

  15. 15

    I am trying to select data from 2 mysql tables into 1 query

  16. 16

    Purpose and usage of the optional parameter (additional) of the method data_for from the data_magic class

  17. 17

    Is there any way to find out the tables relationship?

  18. 18

    连接的data.tables副本

  19. 19

    Event called when sorting data in kendo grid

  20. 20

    Access to an Exception caught by the caller of a method

  21. 21

    如何从Vuetify v-data-table获取过滤的数组?

  22. 22

    如何在Vuetify v-data-table上对齐标题

  23. 23

    Vuetify,为v-data-table tr动画

  24. 24

    Vuetify:通过多个值搜索v-data-table?

  25. 25

    如何清除v-data-table中的选定行,Vuetify

  26. 26

    Select count from four tables

  27. 27

    SELECT query from 2 tables

  28. 28

    Angular js: Access data filtered in ng-repeat (ngRepeat) from controller

  29. 29

    Retrieve data from SQL Server database using ajax method C#

热门标签

归档