A guide on integrating images into a Vue.js Datatable

Hey everyone, I'm facing an issue trying to display an image within a Datatable field. I've attempted various solutions but nothing seems to be working for me,

Currently, my code looks like this:

<q-table
    :data="driverTable.data"
    :columns="driverTable.columns"
    row-key="objectId"
  >
    <template v-slot:no-data="{ icon, message, filter }">
      <div class="full-width row flex-center q-gutter-sm">
        <q-icon size="2em" name="sentiment_dissatisfied" />
        <span>{{ message }}</span>
        <q-icon size="2em" :name="filter ? 'filter_b_and_w' : icon" />
      </div>
    </template>

    <template v-slot:top="props">
      <q-btn flat round dense
        @click="props.toggleFullscreen" color="grey-8" class="q-ml-md"
        :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
        :v-bind="props.inFullscreen"
        :title="props.inFullscreen ? 'Minimize' : 'Full Screen'"
      />
    </template>
  </q-table>

As for my JavaScript code:

data () {
    return {
      driverTable: {
        columns: [
          {
            name: 'objectId',
            field: row => row.objectId,
            format: val => ''
          },
          {
            name: 'name',
            label: 'Full Name',
            align: 'left',
            field: row => row.name,
            format: val => `${val}`,
            sortable: true,
            classes: 'ellipsis'
          },
          {
            name: 'carPermit',
            required: true,
            label: 'Permit',
            field: row => row.carPermit, //
            align: 'center',
            format: val => `${'<img height="75%" width="75%" src="' + val + '"/>'}`
          }
        ],
        data: []
      }
    }
  }

I have attempted using the <img> tag within the field format and appending the URL source to it, however, it only displays the tag as a string in the format.

Answer №1

Kindly follow the instructions provided below:

<q-table
        :data="driverTable.data"
        :columns="driverTable.columns"
        row-key="objectId"
    >
        <template v-slot:no-data="{ icon, message, filter }">
            <div class="full-width row flex-center q-gutter-sm">
                <q-icon size="2em" name="sentiment_dissatisfied" />
                <span>{{ message }}</span>
                <q-icon size="2em" :name="filter ? 'filter_b_and_w' : icon" />
            </div>
        </template>

        <template v-slot:top="props">
            <q-btn flat round dense
                   @click="props.toggleFullscreen" color="grey-8" class="q-ml-md"
                   :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
                   :v-bind="props.inFullscreen"
                   :title="props.inFullscreen ? 'Minimize' : 'Full Screen'"
            />
        </template>
        <template v-slot:body-cell-carPermit="props">
            <q-avatar>
                <img :src="props.row.carPermit">
            </q-avatar>
        </template>


    </q-table>

In addition, please eliminate the format and field keys from cardPermit

data () {
return {
  driverTable: {
    columns: [
      {
        name: 'objectId',
        field: row => row.objectId,
        format: val => ''
      },
      {
        name: 'name',
        label: 'Full Name',
        align: 'left',
        field: row => row.name,
        format: val => `${val}`,
        sortable: true,
        classes: 'ellipsis'
      },
      {
        name: 'carPermit',
        required: true,
        label: 'Permit',
        align: 'center',
      }
    ],
    data: []
  }
}

}

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

Adding query parameters to the end of every link on a webpage

Wondering how to automatically add GET values to the end of each anchor href on a webpage? For instance, if you input google.com?label=12&id=12 I want to ensure that "?label=12&id=12" gets added to the end of every single href in an anchor tag on ...

Creating a unique identifier in JavaScript: the ultimate guide

Hi, I'm new to JavaScript and have been working hard to create a script that copies the text inside <p></p> elements. However, my current script requires different IDs for each <p></p>. Here is the code: function copyToClipboar ...

Calculate the difference to obtain a whole number from the overall length of the array [JavaScript]

Here is the code I am working with: function likes(names) { if (names.length == 0) { return 'no one likes this'; } else if (names.length >= 4) { return names[0]+ ', ' + names[1] + ' and' + names.length - 2 + &ap ...

Is it preferred to utilize v-show in combination with v-for?

I understand that using "v-if" with "v-for" is discouraged, but I'm unsure about the case of "v-show" since it simply toggles the display attribute. Here is the code for reference. Essentially, I am trying to switch between 3 different types of fi ...

What is the best way to integrate Emotion styled components with TypeScript in a React project?

Currently, I am delving into TypeScript and attempting to convert a small project that utilizes Emotion to TypeScript. I have hit a roadblock at this juncture. The code snippet below export const Title = styled.div(props => ({ fontSize: "20px", ...

Issue with Three.js: The mouse hover effect does not revert back to the previous color

Currently, I am working on creating a pattern using Three.js. The goal is to change the color of a face to gray when the user hovers over it with the mouse, and then revert it back to its original light blue color when the mouse moves away. Unfortunately, ...

Oops! You can only have one parent element in JSX expressions

I'm working on creating a password input box, but I keep encountering an error when integrating it into my JS code. Here's the snippet of my code that includes TailwindCSS: function HomePage() { return ( <div> <p className=&q ...

What could be causing the Monster model to not appear when using the glTFLoader in three.js on iOS?

-Details- three.js version : r84 (current version) Device : iPad Air2 iOS version : 10.0.2 Browser : Chrome, Safari -glTFLoader- URL : Monster -> NOT visible The rest -> visible Why am I asking this question? I have encountered a similar is ...

Modifying button attribute through dropdown selection

In my project, I have a dropdown that gets its data from a database. Depending on the selection made in the dropdown, I would like to change the attribute of a button (data-uk-modal="{target:'#modal-'value of dropdown'}"). <select id "ci ...

Module import in Ionic

I'm encountering an issue with Ionic, Angular, and TypeScript, and I'm feeling a bit lost... I'm trying to call an external function from my file but I keep getting the following error: "Uncaught (in promise): TypeError: undefined is not an ...

Using the functionalities of vue-tel-input: A step-by-step guide

After successfully installing the vue-tel-input component and adding it to my project, I am eager to utilize the validate event mentioned in the documentation available at this link. However, I seem to be facing issues in implementing it within the com ...

Why isn't my JavaScript variable visible in the HTML code?

I am currently facing an issue with my Angular app where I am trying to display a JavaScript variable in HTML. The variable successfully shows up in an older part of my application, but it fails to do so in the new section. Below is the functional code sn ...

What is the process of emphasizing a WebElement in WebdriverIO?

Is there a way to highlight web elements that need to be interacted with or asserted in webdriverIO? Or is there a JavaScript code similar to the javascript executor in Selenium that can be used for this purpose? ...

Toggle the visibility of HTML elements by utilizing a JavaScript checkbox event

I have put together these JavaScript functions to hide the delivery address fields on my shopping cart address form if the goods are being sent to the billing address. The functions control the visibility of the HTML wrapped by... function getItem(id) { ...

Retrieve the content of each div element based on its text value

In this particular structure, I have: <table id="thetable"> <tr> <td> <div> <div>some text</div> <div> <div></div> ...

Using jqgrid to customize column header tooltips which are distinct from the actual column label

From what I gather, there are multiple methods for setting distinct column header tooltips. At the moment, my approach involves using jQuery's .attr() to set the tooltips. I'm curious if there is a more streamlined way to save the custom header ...

What are effective ways to eliminate cross-origin request restrictions in Chrome?

Just starting out with angular and trying to incorporate a templateUrl in an angular directive. However, when attempting to view the local html file in the browser, I encounter the following errors --> XMLHttpRequest cannot load file:///Users/suparnade ...

Versioning resources in Spring MVC with Thymeleaf

https://i.sstatic.net/ArllV.png Struggling with resource versioning in Spring Mvc 4 while using thymeleaf template engine. Despite the code provided, I am unable to see the new version URL when viewing the page source. What could be causing this issue? Wh ...

Is your Vue.js chart malfunctioning?

I have been experimenting with chart.js and vue.js. The component I created is called MessageGraph, and it is structured like this (with data extracted from the documentation): <template> <canvas id="myChart" width="400" height="400">< ...

Having trouble getting array push to work in Internet Explorer 5 with JavaScript?

Every time I attempt to populate the select options into the optStored array using array push, the array remains empty. The code works fine in Chrome, Firefox, and Safari but not in Internet Explorer. Is there a workaround for this issue or is it something ...