New Vuetify component for customizing data iterators with specific key names

Can I customize the key names in the Vuetify v-data-iterator component?

https://i.sstatic.net/Znv41.jpg

I need to change the header names without altering the property names inside the "items" array. How can I achieve this when dealing with special characters like ä, ë, ß, etc?

HTML:

<div id="app">
  <v-app id="inspire">
    <v-container fluid>
      <v-data-iterator
        :items="items"
        :items-per-page.sync="itemsPerPage"
        :page.sync="page"
        :search="search"
        :sort-by="sortBy.toLowerCase()"
        :sort-desc="sortDesc"
        hide-default-footer
      >
       ...
      </v-data-iterator>
    </v-container>
  </v-app>
</div>

JS:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data () {
  ...
  },
  computed: {
    numberOfPages () {
    ...
    },
    filteredKeys () {
    ...
    },
  },
  methods: {
    nextPage () {
    ...
    },
    formerPage () {
    ...
    },
    updateItemsPerPage (number) {
    ...
    },
  },
})

This approach is not working for me:

keys: [
  'Custom name for Name',
  'Custom name for Calories',
  ...
],
items: [
  {name: 'Frozen Yogurt', calories: 159, ...},
  ...
]

Demo code: https://codepen.io/noobmaster2137/pen/GRNrddz

Answer №1

You establish a dictionary that links keys to personalized names:

let customNames = {
  key1: "Custom name 1",
  key2: "custom name 2",
  //...
}

Afterward, you utilize those values in the default slot template:

// ...
<v-list-item
  v-for="(key, index) in filteredKeys"
  :key="index"
>
  <v-list-item-content :class="{ 'blue--text': sortBy === key }">
    {{ customNames[key] || key }}: // Show custom names if available
  </v-list-item-content>
  <v-list-item-content
    class="align-end"
    :class="{ 'blue--text': sortBy === key }"
  >
    {{ item[key.toLowerCase()] }}
  </v-list-item-content>
</v-list-item>
// ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having difficulty asserting the dual-function button in both its disabled and enabled states

I have a button that is part of a dual-action setup. This button is disabled until a certain event occurs. Here is the DOM structure while the button is disabled: <div class="doc-buttons"> <a href="#" onclick="actualsize();" id="tip-size" cla ...

Using Vanilla JavaScript to Disable a Specific Key Combination on a Web Page

On a completely random English-Wikipedia editing page, there exists a way to add content (for example, "test") and save it using the existing key combination of Alt+Shift+S. My goal is to specifically prevent this action without removing the save button b ...

What is the best way to exit a for loop in jQuery?

let intervalTime = 800; for(let index = 1; index < 20; index++) { $("#slide"+index).delay(intervalTime).fadeIn(); intervalTime = intervalTime + 800; } Every time I click on a button, the value of "i" should reset to "0". I h ...

Need to import Vue component TWICE

My question is simple: why do I need to import the components twice in the code below for it to function properly? In my current restricted environment, I am unable to utilize Webpack, .vue Single File Components, or npm. Despite these limitations, I mana ...

Utilizing Vector3 for Parametric Geometry calculations

As I update a script to a newer version of three.js, I encountered an issue with ParametricGeometry. The error message "THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter" keeps appearing. Below is the section of code causing t ...

Unable to expand Bootstrap navbar due to collapsing issue

I recently implemented a collapsed navbar on my website using bootstrap. However, I'm facing an issue where it does not open when clicking on the hamburger menu. After researching various solutions for this problem and trying them out, none of them s ...

Converting Plain JSON Objects into a Hierarchical Folder Structure using Logic

Looking at the data provided below: [ {name: 'SubFolder1', parent: 'Folder1'}, {name: 'SubFolder2', parent: 'SubFolder1'}, {name: 'SubFolder3', parent: 'SubFolder2'}, {name: 'Document ...

Angular6 HttpClient: Unable to Inject Headers in Get Request for Chrome and IE11

Under my Angular 6 application, I am attempting to make a GET request while injecting some custom Headers: Here is how my service is structured: @Injectable() export class MyService { constructor(public httpClient: HttpClient) { } getUserInfos(login): Ob ...

What is the best way to handle parsing JSON with special characters in JavaScript?

Content stored in my database: "Recommended cutting conditions" When using Json_encode in PHP, the result is: {"table1":[{"Item":{"original_text":"\u63a8\u5968\u5207\u524a\u6761\u4ef6 \b"}}]}; In JavaScript : var str ...

Using regular expressions to replace all special characters, excluding dots

$('#price').keyup(function(){ $('#price').val($('#price').val().replace(/[_\W]+/g, "-")); }) Experience it firsthand here: http://jsfiddle.net/2KRHh/6/. In the scenario above, special characters are eliminated. ...

Sending array data from the client-side JavaScript to the Spring MVC controller via AJAX

Is there a way to send an array from JavaScript in a web browser to a Spring MVC controller using AJAX? Here's the JavaScript code I have: var a = []; a[0] = 1; a[1] = 2; a[2] = 3; // Is it possible to send multiple arrays as well? $.ajax({ typ ...

Error: The 'price' property is undefined and cannot be read at path C:NODEJS-COMPLETE-GUIDEcontrollersshop.js on line 45, character 37

I have been attempting to add my products to the cart and calculate the totalPrice, but I keep encountering an error. Here is the error message:- enter image description here. Below is the code from my shop.js file:- exports.postCart = (req, res, next) =&g ...

Using Mongoose to Populate an Array with a Referenced Property

In the Post schema, I am using an array of Tags: tags: [ { type: Schema.Types.ObjectId, ref: 'Tag' } ], The Tag schema has the following structure: { name: String } When I populate the tags array, it populates with tag object literals. Is th ...

Utilizing Vuetify color variables in combination with ternary operators: A guide

I'm experimenting with conditional logic to dynamically change the background color of a button. I've seen examples using the ternary operator to do so, but haven't come across any that utilize color variables defined in the theme options. I ...

Select box in material design does not show an error when the value is empty

<md-input-container flex-gt-xs> <label translate>rule.type.title</label> <md-select name="type" ng-required="true" ng-model="vm.model.type" ng-change="vm.onRuleTypeChange(vm.model.type)"> <md-op ...

Are you struggling with Grails - Ajax submission not functioning properly?

Trying to update a div when a form is submitted, but it seems like something is missing. Here's the HTML code: <%@ page contentType="text/html;charset=UTF-8" %> <html> <head> <meta name="layout" content="main" /> ...

Applying colors from the chosen theme

I've implemented in the following way: import React, { Component } from 'react'; import { AppBar, Toolbar } from 'material-ui'; import { Typography } from 'material-ui'; import { MuiThemeProvider, createMuiTheme } from ...

What is the process for accessing the mesh in Aframe when a 3D object is loaded dynamically?

Is there a way to access mesh information of a 3D object loaded at runtime in Aframe? My method for loading the 3D model is as follows: targetObj = document.createElement('a-obj-model'); targetObj.setAttribute('gltf-model', '#wha ...

Showcasing uploaded pictures during development mode with the combination of Meteor and Vue

After spending a considerable amount of time, I finally got the file upload functionality working. Using Vue on the frontend and Meteor on the backend, I managed to successfully upload files using Meteor-Files from VeliovGroup. However, I encountered an is ...

Unlimited scrolling feature on a pre-filled div container

Looking for a way to implement infinite scroll on a div with a large amount of data but struggling to find the right solution? I've tried various jQuery scripts like JScroll, MetaFizzy Infinite Scroll, and more that I found through Google search. Whi ...