Populate Vue 3 Element-plus Virtualized Table with actual data

As a newcomer to frontend development, I am currently working on integrating Element-plus Virtualized Table with actual data. Here is the basic structure of the example:

const generateColumns = (length = 10, prefix = 'column-', props?: any) => {
    return Array.from({ length }).map((_, columnIndex) => ({
        ...props,
        key: `${prefix}${columnIndex}`,
        dataKey: `${prefix}${columnIndex}`,
        title: `Column ${columnIndex}`,
        width: 150,
  }))
}

const generateData = (
    columns: ReturnType<typeof generateColumns>,
    length = 200,
    prefix = 'row-'
) => {
    return Array.from({ length }).map((_, rowIndex) => {
        return columns.reduce(
            (rowData, column, columnIndex) => {
                rowData[column.dataKey] = `Row ${rowIndex} - Col ${columnIndex}`
                return rowData
            },
            {
                id: `${prefix}${rowIndex}`,
                parentId: null,
            }
        )
    })
}

const columns = generateColumns(10)
const data = generateData(columns, 1000)

I have some real data similar to this:

const fetchedData = [
    { address: "...", protocol: ["..."], email: ["..."] },
    { address: "...", protocol: ["...", "..."], email: ["..."] },
    { address: "...", protocol: ["..."], email: ["...", "..."] },
];

The main question at hand is how to adapt my actual data into the functions mentioned in the example code?

Answer №1

<script setup lang="ts">

let employees = await employeeStore.getEmployees(10,0,'updated_at~desc');


const headers = ['name', 'comapny name', 'registered at', 'updated at']

const generateColumns = (length = employees.length, prefix = 'column-', props?: 
any) =>
Array.from({ length }).map((_, columnIndex) => ({
...props,
key: `${prefix}${columnIndex}`,
dataKey: `${prefix}${columnIndex}`,
title: `${headers[columnIndex]}`, // edited content
width: 250,
}))

const generateData = (
columns: ReturnType<typeof generateColumns>,
length = employees.length,
prefix = 'row-'
) =>
Array.from({ length }).map((_, rowIndex) => {

return columns.reduce(
  (rowData, column, columnIndex) => {
    // rowData[column.dataKey] = `Row ${rowIndex} - Col ${columnIndex} 

                      // edited content //

    rowData['column-0'] = `${employees[rowIndex].first_name}`
    rowData['column-1'] = `${employees[rowIndex].email}`
    rowData['column-2'] = `${employees[rowIndex].created_at}`
    rowData['column-3'] = `${employees[rowIndex].updated_at}`
    return rowData
  },
  {
    id: `${prefix}${rowIndex}`,
    parentId: null,
  }
)
})

const columns = generateColumns()
const data = generateData(columns)
</script>

// within your template code

<template>

 <el-table-v2
    :columns="columns"
    :data="data"
    :width="1000"
    :height="400"
    fixed       
    />

</template>

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

Utilizing Vuejs to initiate a GET request using a method

Currently, I am working on enhancing the functionality of a GET request in Vue. My goal is to attach the request sending action to the form's submit button and also include a parameter from a text field within the form. HTML <html> <head> ...

Tips for utilizing both the Element Selector and Class Selector in Jquery

I am working with a simple table that has TDs assigned either the 'PLUS' or 'MINUS' class. My goal is to use jQuery to implement functionality for collapsing all or expanding all. When the Expand All button is clicked, I need to chang ...

Challenges with jQuery Form validation and submitting entries

I am having some issues with my form validation using jQuery. The current setup is working well, but I need to make a specific change that I am struggling with due to my limited knowledge of jQuery. I want to ensure that text boxes, such as first name an ...

Is there a way to access and invoke a exposed function of a Vue component within a default slot?

Exploring the realms of a vue playground. The functions interfaceFunction in both ChildA and ChildB are exposed. In App, these functions can be called by obtaining references to the components that expose them. This allows direct function calls from with ...

One approach to animating elements on a web page is by utilizing Node.js

Imagine you want to programmatically define animated movement for elements on a web page. In JavaScript, this can be achieved using techniques outlined in this helpful guide: How TO - JavaScript HTML Animations. But how would you do this in Node.js? UPDAT ...

Tips for continuously randomizing colors in p5.js

I recently began exploring p5.js and I have a query regarding color randomization. Currently, it seems that the color only changes randomly when I restart the code. Is there a way to trigger this randomization every time the mouse is clicked? Below is the ...

Identify the Presence of Hover Functionality

For a while now, the trend has been leaning towards feature detection. I am interested in determining whether a visitor's browser supports the :hover pseudo class. With many mobile devices not supporting hovering, I want to adjust my event listeners a ...

Developing a multi-language Laravel Vue website with string keys for translations

I've been on the lookout for a simple solution without plugins. In my translation file, I'm using Laravel's string as key format. Inside the fr.json file, all texts and their translations are stored. It functions well with Blade, but I&apo ...

Having trouble executing a Vue project as I encountered an error stating: "Module not found: '@vue/cli-plugin-babel'". To fix this, I proceeded to install the necessary dependencies by running the command: npm install

Error: The module '@vue/cli-plugin-babel' could not be found. Require stack: C:\Users\HP\AppData\Roaming\npm\node_modules@vue\cli-service\lib\Service.js C:\Users\HP\AppData\Roaming ...

What happens when there is no match found while attempting to edit a form with the UI-Bootstrap typeahead directive?

Here is the code that demonstrates how my typeahead input box functions. Users can enter a name, and the relevant information will populate the rest of the form. If no match is found, users should still be able to input the name and related details into th ...

Jquery plugin experiencing a malfunction

I am encountering an issue with my custom plugin as I am relatively new to this. My goal is to modify the properties of div elements on a webpage. Here is the JavaScript code I am using: (function($) { $.fn.changeDiv = function( options ) { var sett ...

Tips for resolving the error "Parsing near 'Unexpected end of JSON input while parsing...' for...'mocha':'^3.2.0','s'":

Once I've successfully set up react and react-dom, the next step is to install webpack. However, I encountered an error during this process. To troubleshoot, I decided to install babel-loader first to ensure that both npm and my internet connection a ...

Struggling to implement dynamic templates in an Angular directive

In the process of developing a small angular application that consists of 3 modes - QA, Production, and Sandbox. In the QA mode, there are multiple buttons for users to select values which then populate "myModel". The other two modes, Production and Sandbo ...

How can I make sure addEventListener only responds to numbers and not images?

Currently, I am facing a dilemma with implementing a button that features an image on it and needs to be placed within another div. Despite successfully achieving this, I am struggling to comprehend the JavaScript code outlined in a tutorial I followed. Th ...

Generate available choices for an asp:DropDownList using JavaScript without relying on the client-side ID

Can options be populated in an asp:DropDownList using JavaScript without the need for getElementById? I prefer a selector that utilizes classes. Appreciate any assistance. Goodbye. ...

Guide to Triggering a Page View Event in Google Tag Manager with Angular

Previously, I manually fired the Page View Event using JavaScript from app.component.ts while directly accessing Google Analytics: declare var gtag: Function; ... constructor(private router: Router) { const navEndEvents = this.router.events.pipe( fil ...

Understanding the flattening process of arrays using JavaScript - Detailed explanation required

Currently, I am immersed in the captivating world of Eloquent JavaScript. However, I have hit a roadblock with one of the exercises that involves flattening a multi-dimensional array. Despite my best efforts, I have been unable to crack the code. After f ...

NodeJS constantly communicating with Rest API

Entering the world of Node.js is a new journey for me. I have a service with two endpoints available. The first endpoint is a post method that takes in a payload, processes it asynchronously, and immediately sends an acknowledgment to the caller. The secon ...

Unable to utilize the "fs" module within a Three.js application

After utilizing this base code to create an app with Three.js, I attempted to incorporate node's fs module for filesystem interaction. Despite adding const fs = require("fs") in my app.js file, the module could not be located. The error mess ...

`Generating an ever-changing masonry layout on a website using live data`

I'm currently working on a new web project and I want to incorporate a masonry view for the images on the homepage. The plan is to host this project on Azure, using blob storage for all the images. My idea is to organize the images for the masonry vi ...