Output information from UI Grid

Currently, I am utilizing ui-grid version v3.2.9 with the aim of printing data that has already been displayed in UI.
My table structure consists of div elements created using Angular UI Grid.
Here's my current approach:

I open a new window and append the HTML of the grid to it. Then, I invoke the window.print() method to print all the content within this newly opened window.

However, I encountered an issue where if there are numerous records in my grid, a vertical scroll appears in the newly opened window. When I use the window.print() method, it only prints the visible area instead of all the content present in the window. Below is the pseudo code snippet I have used:

function print(id){
  var print = document.getElementById(id);  
  var w = window.open("", "");  
  var headContent = document.getElementsByTagName('head')[0].outerHTML;  
  var writeMe = ('<html><body><head>' + headContent + '</head>');  
  writeMe += (print.outerHTML);  
  writeMe += ('</body></html>');  
  w.document.write(writeMe);  
  w.document.close();  
  w.focus();
  w.setTimeout(function(){
    w.print();
    w.close();
  }, 1000);  
}

I am seeking suggestions on how I can enhance my code to successfully print the entire content of the window. Any insights would be greatly appreciated! Thank you!

Answer №1

Kindly consider adding an ID to the row or grid for printing purposes

<head>
    <style type="text/css">

    #printable { display: none; }

    @media print
    {
        #non-printable { display: none; }
        #printable { display: block; }
    }
    </style>
</head>
<body>
    <div id="non-printable">
        Your regular page content
    </div>

    <div id="printable">
        Print-friendly version
    </div>
</body>

Code snippet for determining visible area

function visibleArea(){
     var pwidth = $(window).width();
     var pheight = $(window).height();
        var top = $(this).scrollTop();       
       $("h1").html("total visible area is from:"+ top +" to "+ (pheight + top) +"px"); // include printable id and other non-printable elements

}

If you have an ID, you can pass it like this in the function

  function printpage(){
    var originalContents = document.body.innerHTML;
    var printReport= document.getElementById('div1').innerHTML;
    document.body.innerHTML = printReport;
    window.print();
    document.body.innerHTML = originalContents;
}

Answer №2

If you're facing issues with media queries, try using this specific CSS code:

@media screen and (max-width: 768px) {
   .yourDivClass {
     display: block;
     margin: 0 auto;
     padding: 10px;
   }
}

Make sure to test it out on different devices to ensure it works effectively!

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

Exploring the best practices for loading state from local storage in VueJS/NuxtJS by leveraging the "useLocalStorage" utility

When attempting to utilize useLocalStorage from pinia, I am encountering an issue where the data in the store's state is not fetched from local storage and instead defaults to the default value. Below is the code snippet from my store method: import ...

Angular is not programmed to automatically reflect updates made to my string array

let signalRServerEndPoint = 'https://localhost:44338'; this.connection = $.hubConnection(signalRServerEndPoint); this.proxy = this.connection.createHubProxy('MessagesHub'); this.proxy.on("ReceiveMessage", (message) => { ...

The module script failed to load due to an unexpected response from the server, which was MIME type of text/jsx instead of a javascript module script

I have recently set up an express server and created an API, as well as installed React using Vite for my frontend. However, when I attempt to connect or load my main HTML file to the server, an error is displayed in the console. This is all new to me as I ...

"Discovering the magic behind leaflet js's method of fetching tiles directly from

If you imagine tiles being stored in a file system similar to the image shown below https://i.sstatic.net/6NryK.png You can take a quick look at this URL Take a look at the code var map = L.map('map').setView([0, 0], 2); L.tileLayer(& ...

Achieving secure HTTPS connection with socket.io

At the moment, my setup involves: let connectTo = "http://myip:myport"; var socket = io.connect(connectTo, {secure: true}); on the client side and const port = myport; const io = require('socket.io')(port); on the server side. I am looking to ...

A guide on using .map() with meta tags in Next.js

My goal is to map the content of meta, but currently my code is replicating multiple instances of the entire meta tags. Here is the code I have: {general.head.articleAuthor.en.map(( ) => ( <meta property="article:author" content={general.h ...

Issue with Click event not working on dynamically added button in Angular 8

My goal is to dynamically add and remove product images when a user clicks the add or delete button on the screen. However, I am encountering an issue where the function is not being called when dynamically injecting HTML and binding the click event. Below ...

Show a loading screen or spinner while waiting for a response from a REST API using JavaScript

I am currently developing a chrome extension that interacts with an exposed REST Service to send and receive data. To improve the user experience, I want to display a loading indicator while waiting for a response from the API server. However, due to the a ...

Experiencing a scroll problem in the latest version of Google Chrome for Android while using ReactJS? The issue seems to have migrated from the earlier version 99.xxxxxx to

Previously, my website was functioning perfectly in full screen mode. However, after updating Chrome on Android to the latest version (116.xxxxxx....), I noticed that it is now displaying a scrolling behavior that was not present in the earlier version (99 ...

Instructions on creating an input field and a slider simultaneously

Currently, I am exploring the world of CSS 3D transforms and I am particularly interested in creating sliders to manage these transforms. I recently stumbled upon the Three.js editor and was impressed by how it handles the positioning, rotation, and scalin ...

Error in Angular html5 mode: [ngRepeat:dupes] It is prohibited to have duplicate items within a repeater

Can you please help me troubleshoot this code issue? I am receiving an Error in the console: Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: category in categories, ...

Ignore non-existent items in React-Native by filtering them out

I'm currently faced with a scenario where I need to loop through an array of objects. Specifically, when there are more than two objects in the array and the first object is missing, how can I skip it and move on to the next one? Check out the loop b ...

Exploring protractor and webdriver basics in the context of a non-angular application

Currently, I am in the process of writing end-to-end tests for a non-angular application using Protractor. While there is a wealth of information available on how to achieve this, it appears that there are multiple approaches to consider. This has led me ...

org.openqa.selenium.UnexpectedAlertOpenException: error occurred due to an unanticipated alert opening

While using the Chrome Driver to test a webpage, I typically have no issues. However, there are times when exceptions occur: org.openqa.selenium.UnhandledAlertException: unexpected alert open (Session info: chrome=38.0.2125.111) (Driver info: chromedri ...

When using TypeScript types with JSX.Element in React, attempting to use .map() will result in an error message with code TS2339

I have decided to build a calendar using table elements and TypeScript. This is my first experience with TypeScript and I am facing an issue where my type is not being accepted. As you can see in the code snippet below, I am using JSX elements as placehold ...

Updating content with Ajax in Laravel

Hey, I'm currently facing an issue with my update functionality. Below is the blade code snippet: <div class="form-group floating-label" id="role_colaboration1"> <select name="{{$role}}[]" id="role" class="form-control"> ...

Having trouble with Javascript in getting one-page scroll navigation to work?

Hey there, I am working on creating a one-page scroll navigation with some basic javascript to add a smooth animation effect that takes 1 second as it scrolls to the desired section. However, I seem to be experiencing an issue where it's not functioni ...

Can I apply a different color to every row in an HTML selector?

My question involves using an HTML selector that allows the user to choose a color. <select name="color" class="form-control"> <option value="ff0000">Red</option> <option value="ff7f00">Orange</option> <option value= ...

"Adhesive" option in Angular application

Encountering a frustrating issue with an Angular-based frontend app. A select box seems to be stuck and requires double selection to change the option. Below is a code snippet that demonstrates the problem: <script src="https://ajax.googleapis.com/aj ...

Is it possible to utilize the Vuejs router routes array to dynamically generate a navigation menu?

Below is the code I am using to set up VueJS routes and pass them into a router: export const routesArray = { routes: [ { path: '/', name: 'Add Stash', component: Form }, { path: '/log', ...