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

Problem with updating an Html.TextBoxFor based on the value of another one

I have been trying to implement a basic jQuery functionality that involves changing the text in one textbox to be half of the numeric value entered in another textbox. Below is the script I am using: <script> $(document).ready(function () { $(& ...

Troubleshooting KuCoin API: Dealing with Invalid KC-API-SIGN Error and FAQs on Creating the Correct Signature

I want to retrieve open orders for my account using the following code snippet: import { KEY, PASSWORD, SECRET } from "./secrets.js"; import CryptoJS from "crypto-js"; const baseUrl = 'https://api.kucoin.com' const endPointOr ...

Effortlessly accessing API with AJAX login using jQuery

I'm trying to implement a login form using AJAX and jQuery for an API. When I run the following command in the terminal: $ curl -d '[email protected]&password=123123' The response includes a hash containing an API token and Auth I ...

What is the process for pulling out a specific JSON element based on a condition?

I am working with a JSON object that looks like this: "links" : [ { "rel" : "first", "href" : "http://localhost:8080/first" }, { "rel" : "self", "href" : "http://localhost:8080/self" }, { "rel" : "next", "href" : "http://loca ...

Fetching data from a server using Angular and displaying it in controllers

I am currently working on a project where I need to retrieve JSON files and their content using a factory in AngularJS. My main goal is to make this data accessible to other controllers, but I am struggling with getting the factory to return the deityData. ...

What is the correct way to update an array of objects using setState in React?

I am facing an issue where I have an array of objects that generates Close buttons based on the number of items in it. When I click a Close button, my expectation is that the array should be updated (removed) and the corresponding button element should dis ...

Struggling to retrieve information from a JSON file and display it within a component?

After accessing the JSON data and storing the necessary values in a dictionary named details, I am encountering an issue where the values are displayed when console logged from inside the function but appear as undefined when console logged in the parent f ...

Hidden button trigger is malfunctioning

I am attempting to activate a hidden button, but the event does not seem to be triggering. Here is the code snippet: <div class="dyn-inp-group"> <div class="dyn-inps"> <div class="form-group form-group-options col-xs-12 dyn-inp" ...

Improve the Jquery event binding to prevent any potential repetition in code

Is there a more professional and organized way to write this code? I find it a bit messy as it is. The code currently submits a form either by pressing "Enter" key or clicking the mouse. Is there an alternative method that can be used? $("#form-signup-lo ...

Currency unique to a specific culture

Recently, I encountered an issue while working on a website that involved using JavaScript code to format currency values. Here is the snippet of code that was causing the problem: UsdAmount.toLocaleString(siteCulture, {style: 'currency', ...

if the condition is not met, proceed to the alternate template eventually

Hey there, I'm facing an issue with my code that resembles something like this: <ng-container *ngIf="firstCondition; else Farewell"> <ng-container *ngIf="innerContainer"> <div class="Hello Message"> {{HelloMessa ...

Guide to inputting text into the Dev element

I am encountering a challenge with automating gist creation on GitHub. The issue arises when trying to input text into the gist content-box (see attached image). Despite attempting to use Javascript executer, I have not been successful. JavascriptExecutor ...

Ensuring the child div's height does not overflow beyond the parent div

When dealing with a parent div and a child div, both having different heights, how can I specifically retrieve the height of the portion of the child div that is within the boundaries of the parent div? Using document.getElementById("id").style.height prov ...

I'm having trouble sending registration emails through my server. What could be causing this issue?

Currently, I am in the process of developing a registration system that automatically sends an email with the user's username and password once they have successfully registered. The registration process functions smoothly up until the point where the ...

Maintaining hover functionality of menu button while navigating through sub-menu options

Creating a CSS dropdown menu is straightforward, but maintaining the hover state on the main menu button while navigating through the dropdown selections can be tricky. In the past, I used JavaScript to change the class and retain the background image, but ...

The Jquery slider panel seems to be stuck open even after I switched its CSS orientation from right to left

I am following up on a previous question, which can be found here. After fixing the jQuery code, I decided to change the panel slider to open from the left side instead of the right. I modified the class from "cd-panel from-right" to "cd-panel from-left". ...

Learn how to display two different videos in a single HTML5 video player

Seeking a solution to play two different videos in one video element, I have found that only the first source plays. Is jQuery the answer for this problem? HTML Code: <video autoplay loop id="bbgVid"> <source src="style/mpVideos/mpv1.mp4" type ...

Determining with jQuery if the right element has been successfully "dropped"

Imagine having 10 different draggable boxes and 2 droppable areas. You need to correctly match 5 boxes with droppable area 1 and the other 5 with droppable area 2. If a box intended for droppable area 1 is mistakenly dropped into area 2, it should not wor ...

AngularJS encountering unresponsive resources

When setting up my Angular App, I include various resources like this: angular.module('myApp', ['infinite-scroll', 'chieffancypants.loadingBar', 'ngResource']) Next, in the html file: <script type="text/javascr ...

Codignator does not attach the array elements together

While building a registration form for my website, I encountered an issue with passing single element values into an array in CodeIgniter. The values are not being passed correctly, resulting in an error message about an empty alert. How can I resolve th ...