Interactive tables created using Google Visualization

I have a Google visualization data table that works well, but I am facing an issue with the width of the table. When I click as shown in the image, I call the function drawTable(); and then I encounter this:

As you can see, the table does not have a width of 100%;

However, when I click on "Mehanizacija" again, as shown in the photo, I call the function drawTable() once more and everything is okay:

So, what is causing the problem with the datatable width? Why do I need to call the drawTable() function twice for it to work properly? Is there any way to fix this so that the datatable gets the width: 100% with just one click?

Here is my function drawTable();:

function drawTable() {

  // Create and populate the data table.
  var JSONObject = $.ajax({
                    url: 'call_radnici.php', // make sure this URL points to the correct data file
                    dataType: 'json',
                    data:{ajdi:ajdi},
                    async: false,
                    type: 'POST',
                }).responseText;

  var data = new google.visualization.DataTable(JSONObject, 0.5);

  data.addColumn('string', '');
  for (var y = 0, maxrows = data.getNumberOfRows(); y < maxrows; y++) {
    var mc = data.getNumberOfColumns()-1;
    data.setValue(y, mc, '<div data-toggle="tooltip" data-placement="top" title="Delete this day data"><i class="fa fa-trash-o" ></i></div>');
  }

  var table = new google.visualization.Table(document.getElementById('tplradnici'));

  table.draw(data, {'allowHtml': true,  cssClassNames: {
        'headerRow': 'zaglavlje1',
        'tableRow': 'red',
        'oddTableRow': 'red',
        'selectedTableRow': 'orange-background large-font',
        'hoverTableRow': 'prekoreda',
        'headerCell': 'gold-border',
        'tableCell': 'cell',
        'rowNumberCell': 'underline-blue-font'}
    });

};

Answer №1

Typically, the Table Visualization is set to draw at 100% of the containing div's width. The specific pixel width of the container is defined in the inline style of the <table> element (for example, if the container div is 500px wide, then the <table> element will have a style attribute of width:500px;). If your Table appears narrower than 100% width upon initial drawing, it may be due to placing it inside a hidden div, which can interfere with the Visualization API's dimensional measurements - this commonly occurs when nesting Tables within tab interfaces.

To address this issue, consider implementing a "ready" event handler for the table that adjusts the styles of the internal <table> elements:

google.visualization.events.addListener(table, 'ready', function () {
    var tArr = document.querySelectorAll('#tplradnici table');
    for (var i = 0; i < tArr.length; i++) {
        tArr[i].style.width = '100%';
    }
});

Incorporate this event handler into your code after creating the Table but before rendering it.

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

Setting a default value within an input tag: A step-by-step guide

const [userData, setUserData] = useState([]); const handleUserInfo = (id) => { fetch(`https://602e7c2c4410730017c50b9d.mockapi.io/users/${id}`) .then(res => res.json()) .then(data => setUserData(data)) } <inpu ...

Why do Material UI components fail to render in jsdom while using Jest?

During my UI testing using Jest/React Testing Library, I encountered a peculiar issue. In one of my components, the return statement is structured as follows: const sidebarContentUp = ( <Drawer anchor="left" onClose={onMobileC ...

What methods are available for updating the href color of an element using the DOM?

I am looking to update the color of a tab (Mathematics-tab) based on the value of 'aria-selected' changing to true in Bootstrap. I have multiple tabs, including one for mathematics, and I want to visually differentiate between selected and unsele ...

Organizing layers with Leaflet's layerGroup controls

I am working with a series of Leaflet FeatureGroups, each made up of GeoJSON layers. These FeatureGroups have similar concepts but need to be kept separate for control purposes. I also require the ability to toggle all FeatureGroups on and off simultaneous ...

Utilizing Wordpress for Effective Internal Linking

Looking to set up a Table of Content on a custom Wordpress template, I decided to hardcode the headings for internal sections in advance. However, I'm facing an issue where it doesn't scroll to the intended section in Wordpress. Take a look at th ...

Prevent div from moving upward using CSS

Whenever I use the search box, a dropdown list of suggestions appears. However, the searchbox div element keeps moving both up and down. How can I prevent the div from moving upwards? The code snippet below shows a hardcoded unordered list of names for s ...

Using VML for background images in Outlook using HAML: A step-by-step guide

I am currently working on formatting an email digest using HAML and tables. My goal is to set a background-image to a table-cell in the email, but I've come to realize that Outlook requires VML in order to display a background-image correctly. After ...

Refresh the image source using the AJAX success callback

Previously, I was updating Label values within the AJAX success function as shown below. Now, I am looking for a way to use the same method to change or update the "src" attribute of an <img id="myimage" src=""/> $.ajax({ url: 'clmcontrol_l ...

Achieve identical outcomes with PHP's `strlen` function and jQuery's `val().length` method

Currently, I am utilizing jQuery to dynamically count the value of a textarea: function count_chars () { count_chars=$('#text_textarea').val().length; } Upon submission, I serialize the form and send the textarea text via AJAX to a PHP file ...

On mobile devices, a height of 100vh exceeds the visible screen area

Struggling to cover the entire visible part of the browser window using 100vh due to issues on certain devices and mobile browsers. For example, in Safari, the URL section hides a top part, and similarly on some Android devices using Chrome. https://i.stac ...

What could be causing media queries to not update values even after being changed through JavaScript?

I have a simple navigation bar on my website, featuring links to different subpages. To enhance the user experience on mobile devices, I added a hamburger menu icon that is displayed on smaller screens. The links in the navigation bar are hidden using CSS ...

Managing several instances of NgbPagination on a single webpage

I am facing a challenge with having multiple NgbPagination components on a single page. For more information, please visit: Initially, I attempted to use ids but encountered an issue where changing one value in the first pagination affected both tables. ...

AngularJS - one-time execution of view generation from .NET controller

Currently, I have an MVC .NET application integrated with AngularJS. In my route provider configuration, I am utilizing the controllers of MVC to retrieve the views as shown below: .when('/Units', { templateUrl: 'Unit/Units' ...

Save a SQL query as a text file using Node.js

I'm having an issue with my code. I am trying to save the results of a SQL query into a text file, but instead of getting the actual results, all I see in the file is the word "object." const fs = require('fs'); const sql = require('mss ...

What is the proper method for securing this?

Trying to retrieve 'this' within a method that is invoked by pressing a button, where this points to both the class and the pressed button: p.myVar = 'apple'; $('.go').on('click', this._init); p._init = function(e ...

Storing input values in the state using Typescript by default

Upon launching, my activeField state is initially empty. However, when a user focuses on the field, it gets added to the state. I am encountering a warning in Typescript because when I attempt to update the selectionEnd of that field, it tells me: Property ...

HTML comments generated from Freemarker's list notation

Currently, I have integrated Apache Freemarker into an HTML editor where users can create templates using code. For example, a user may write the following code for a list: <#list items as item>...</#list> While this is the correct way to gen ...

Issue with the gulp-babel plugin: Files within the Plugin/Preset should only export functions, not objects

I have started to integrate JavaScript 2015 (ES6) into my Ionic v1 app: package.json { "name": "test", "version": "1.0.0", "dependencies": { "@ionic-native/deeplinks": "^4.18.0", "cordova-android": "7.0.0", "cordova-android-support-gra ...

Placing an element in a fixed position behind a non-fixed element

I am facing a challenge with an element that has two children, one of them is absolutely positioned. My goal is to position this absolutely placed element behind its sibling. Unfortunately, the z-index property doesn't seem to be working as expected. ...

Is there a way for me to utilize a single set of checkboxes for submitting multiple times in order to generate multiple selections simultaneously?

I'm exploring the idea of using checkboxes that can be dynamically updated and posted to a PHP page multiple times. The goal is to send different sets of selections from the same checkboxes to the PHP page, with each set being treated as data for furt ...