Is there a way to adjust the font size of a vue-good-table within a vue.js project?

I am facing an issue in Vue.js where the content of a page gets "cut off" on the right side when trying to print it. I'm wondering if I should use a function to solve this problem?

<vue-good-table :columns="columns" :rows="rows" id="vgt-table"></vue-good-table>
return {
      dispatchedToText: "",
      columns: [
        {
          label: "Bag Number",
          field: "bagNumber",
        },
        {
          label: "Chit Number",
          field: "chitNumber",
        },
        ....
      ],
      rows: parsedData,
      codes: [],
      users: [],
    };

printContent() {
      const printContents =
        `<br>` +
        `<div style="font-weight: bold; font-size: 25px;">Despatched to Trelleborg</div>` +
        document.getElementById("printable-content").innerHTML;
      const originalContents = document.body.innerHTML;

      document.body.innerHTML = printContents;
      window.print();
      document.body.innerHTML = originalContents;
    },

I have tried applying styles like this:

  <style scoped>
.printOnly {
  display: none;
}
@media screen {

  .vgt-table td {
    font-size: 10px; 
  }
}
@media print {
  body .vgt-table {
    font-size: 12px; 
  }
  .printOnly {
    display: block;
  }
  }
  table {
    padding: 0.3em 0.3em 0.3em 0.3em;
    vertical-align: top;
    border-bottom: 1px solid #dcdfe6;
    color: #606266;
  }
}
</style>

However, the issue persists.

Answer №1

If you are facing a table printing issue in Vue.js, you can resolve it by following these steps:

1. Make adjustments to the table layout for better printing:

 @media print {
  .vgt-table {
    table-layout: fixed;
    width: 100%;
  }
  .vgt-table td, .vgt-table th {
    font-size: 10px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

2. Define print page margins using CSS:

@media print {
  @page {
    margin: 10mm;
  }
}

3. Utilize Vue's "ref" attribute for accessing DOM elements:

<vue-good-table :columns="columns" :rows="rows" ref="vgtTable"></vue-good-table>

4. Update your methods as shown below:

printContent() {
  const printContents = this.$refs.vgtTable.$el.outerHTML;
  // ... add your code here
}

Hopefully, these suggestions will help fix the issue.

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

Using Express.js to import a SQL file

I am facing challenges while attempting to import an sql file into Express JS. I have tried various codes involving the mssql and fs modules, but none seem to be working as expected. fs.readFile(__dirname +'/database.sql', function (err, sqlFile ...

What is the correct way to add type annotations to an Axios request?

I have meticulously added type annotations to all endpoints in my API using the openapi-typescript package. Now, I am looking to apply these annotations to my Axios requests as well. Here is a snippet of code from a Vue.js project I have been developing: ...

Console builds successfully, but encountering issues with building in Docker

Whenever I compile my vite image locally using the following command (found in package.json): "vite_build:dev": "NODE_ENV=test env-cmd -f ./config/.env.dev react-scripts --max_old_space_size=8000 build", everything functions correctly ...

Is there an appropriate method in Vue/Nuxt for managing and altering component data without using lifecycle hooks?

Scenario: I am dealing with a component that showcases a datatable listing Applications. Upon clicking a row, it triggers the opening of another component with appropriately loaded fields (for new or edit). The Challenge: The component loads a reference t ...

Updating the time and date format within an AngularJS application

I am receiving date and time data from the API and would like to adjust the format. The current format is "2016-05-12", "07:17:35". Desired format: 12-May-2016 7:30 PM: <table class="table"> <thead> <tr> <th& ...

Is there a way to continuously make changes to my MEAN stack code without needing to constantly restart `npm start`?

When running my MMEAN stack app (Mongoose, MongoDB, Express, AngularJS, and Node.js) using npm start, I find that every time I make a code change, I have to stop and start npm start again in order for the changes to appear on my web application. The consta ...

Exploring diverse output values in console using JavaScript and jQuery

As someone new to javascript/jquery/html, I've been tasked with creating a small simulator using html and javascript. I have an array containing html ids and a function that updates input based on the state passed to it. The snippet of code looks li ...

Refresh a dynamically loaded webpage following an update

Trying to grasp the concept of reloading a dynamic page loaded with AJAX after a record is updated. Here's the jquery script on the page: <script type="text/javascript> function showUser(str) { if (str == "") { $("#txtHint").empty() ...

What is the process of integrating Bootstrap into a Node project?

I recently set up a MEAN stack project using npm and am currently including Bootstrap via CDN: link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css') However, I want to add Bootstrap using ...

Unable to display array values (using jQuery)

Help! I am having trouble rendering all my values. I have names (buttons) and when I click on them, I want to render the array behind it. Using .append() works, but the issue is that when I click again, it doesn't refresh and gets stacked. I am thinki ...

Having trouble with NPM install because of a node-gyp issue?

We're facing issues with running "npm install" on our project. The error message states that a specific file cannot be located: fatal error C1083: Cannot open include file: 'windows.h' This error seems to be originating from the node-gyp mo ...

Place an element in relation to the vertical size of a div that includes written content

Currently, I am working on implementing a button with a popup that appears underneath it when the user hovers over it. The specific requirements for this setup are: The size of the button should not affect the size of the popup The popup should always be ...

Enhancing radio buttons by swapping them out with images

I am currently working on implementing two key functionalities within this project. 1. Displaying content upon clicking a radio button 2. Replacing the default radio button with images While I could have opted for a simpler solution by using clickable ima ...

A simple guide to fetching JSON data and storing it in a variable, then parsing it and displaying it

I am looking to retrieve JSON data from the Yahoo Finance API, store it in a JavaScript variable, extract specific information such as "name" and "price", and then display it in an HTML table. The JSON data can be accessed via the following link: Current ...

Eliminate the hazy white layer covering the exterior of an image that has been blurred using CSS

Hey there, I've encountered an issue with an image that transitions from blurred to unblurred when the dom is loaded. <div class="image-wrapper-container2"><div class="image-wrapper orig" style="background-image: url('https://www.w3scho ...

Issue with activating a Modal through a button inside a table row on React

I'm currently working on two files: Modal.js and Users.js. Users.js features a table with an API get query linked to it, and in the last column of the table, there's a dropdown for each row that contains three buttons: View, Edit, and Delete. My ...

Firestore query is not displaying the expected data, resulting in an empty array being returned

I've encountered an issue where my query is returning an empty array. Despite double-checking for errors and typos in the query, no error messages are popping up. This problem arose while working on a learning project inspired by Firehip's NextJS ...

Filtering data based on the model in React Native allows you to refine and organize

This code snippet represents a modal that contains two custom dropdown components, a text input, and a button. When the button is clicked, it filters data from an API. Currently, I am struggling to create a functional filter function despite multiple atte ...

A guide on incorporating a customized Google map into your website

Recently, I utilized the Google Map editing service from this site: https://developers.google.com/maps/documentation/javascript/styling This link provided me with two things: 1. A JSON code 2. The Google API link However, I am unsure about how to incorpo ...

Guide to utilizing Vue.js method functions to add a thousand separator in the passed props

As a beginner in Vue.js, I am trying to add a thousand separator to the price passed as a prop using a method called 'thousandSeparator'. However, I am having trouble figuring out how to implement this. I have managed to parse the props price, b ...