The width of table columns is altered upon the second rendering in JQuery DataTables

Is there a way to prevent JQuery DataTables cells from extending width after adding hyperlink to cell?

I am facing an issue where I have two tables on the same page. The first table column has a link which populates the second table. It works fine when the first table is rendered for the first time, but the column width does not remain consistent when rendering the table again.

First Time Table Render:

https://i.stack.imgur.com/b50JK.png

Rendering the Same Table Again:

https://i.stack.imgur.com/DvxzE.png

var tblJanusPlate = $('#tbl').DataTable({
                
"processing": true,
//"serverSide": true,
"bPaginate": false,
"bFilter": false,
"bInfo": false,
"scrollY": "300px",
"scrollCollapse": true,
"bDestroy": true,
"columns": [{
"data": "Name",
"width": "10%"
},

{
"data": "Country",
"render": function(data, type, row, meta) {                  
return "<a href='" + data + "' id= '" + row + "' style='color: black; text-decoration: none;' onclick='return populateDetails(this,\"" + row.Name + "\",\"region\",\"" + regDate + "\");' >" + row.Record_Count + "</a>";
                   
}, "width": "10%"
}
]

});
$.ajax({
type: "POST",
url: "Service.asmx/PlateStats",
contentType: "application/json",
dataType: "json",
data: "{ regDate: '" + regDate + "', type: '" + command + "'}",
success: function(response) {

response = JSON.parse(response);

tblJanusPlate.clear();
tblJanusPlate.rows.add(response[0]).draw(); 

            }
        });

Answer №1

I believe the issue may be related to the "bDestroy" property. However, I could be mistaken so I welcome any feedback.

Upon removing the destroy option, I tested the solution provided in the Datatable manual and it resolved the issue for me.

https://i.stack.imgur.com/gIPuy.png

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

Stack pictures on a slender DIV

I am trying to create a vertical line inside a DIV container. After that, I want to add an image on top of the vertical line (see attached picture for reference). This is what my current source code looks like: <div style="background-color:gray;width ...

jQuery breaks when working with ASP.NET forms

Essentially, it appears that using an ASP.NET page with the <form runat=server> tag can cause some jQuery scripts to break. To illustrate this issue, consider the following scenario: You have a simple webpage with only a checkbox, like so: <inpu ...

Issue with rendering nested UIComponent and actionListener not functioning properly in Primefaces AJAX

UPDATE 2: Understanding the Discrepancy Hey @BalusC, I'm seeking clarity on why this question differs from the post you referenced. My query pertains to an unusual behavior with an actionListener that fails to execute a method. In my examination, I& ...

After the successful completion of the AJAX request, I aim to transmit the identification data via the

Click here for image preview Below is the table content: Using jQuery: <script type="text/javascript> $(document).ready(function(){ $(document).on('keydown','#search',function(){ var input = $(this).val(); ...

Implementing time-limited class addition and removal using jQuery

Upon clicking an icon, a search box should appear. It will then automatically disappear after a certain interval of time (e.g., 5 seconds), even if the user clicks elsewhere on the page. $(".icon").click(function()){ $("search-box").addClass("active ...

Tips for determining whether the current request is an AJAX request in MVC3 view using JavaScript

I have a div with a maximum height and overflow set to auto. When the size of the div overflows, a scroll bar is automatically added. However, I have also set $("#itemsdiv").scrollTop(10000); so that the scroll bar is always at the bottom. Now, I want t ...

Navigating to a precise location on initial page load using Angular 11

Within the structure of my app, I have a parent component that displays a large image from a child component. When the parent component loads, I want the browser window to automatically scroll to a specific position in order to center the image. Currently ...

Having trouble accessing the inline transform scale with jQuery

I am working on a new feature where I need to extract the inline transform scale value from each list item (li). Below is a demonstration for you to assist me: HTML <div style="color:red;transform:scale(1);">Dummy content</div> JS $(functi ...

Personalized sorting to match the unique rendering of cells in Material UI Data Grid

I have integrated the Material UI V4 Data Grid component into my React Js application. The Data Grid component requires two props: rows (list type) and columns (list type). Below is a sample row item: const rows = [ { id: 1, customerName: " ...

Having issues with image hover and click functionality

My website has an image with the cursor set to pointer and a function that should show a hidden element when clicked. However, it's not working at all. When I hover over it or click on it, nothing happens. Here is a screenshot of the issue along with ...

I am having trouble displaying my mysqli table correctly. I could use some help troubleshooting my code as I am unable to locate the error

After implementing Bootstrap, I am facing an issue with the table display on my new page. The code works perfectly fine on the old page, but for some reason, it's not showing correctly on the new one. Upon inspection, I suspect that mysqli_close and a ...

Enhance an existing webpage by integrating ajax with jquery-ui

I'm seeking assistance with integrating an advanced search feature into an existing webpage system. It appears that there is a complication with the current jQuery UI being used on the page: <script src="js/jquery-ui-1.10.4.custom.js"> ...

PHP script is not successfully receiving the Ajax post request that is

As a newcomer to the world of php and ajax, I am facing a challenge in passing a variable from jquery to a php page loaded within a modal window. My php script fetches table information for multiple users. Next to each user's name, there is an edit b ...

Create a straightforward spinning tool using JQUERY

I recently acquired a JQuery plugin from Google designed to detect a "mousehold" event for JQUERY. $('document').ready(function(){ $('#button').mousehold(function(){ //Implementing a spinner here }); }); The mous ...

Using Cordova to create an accordion list on an HTML webpage

I am in need of an accordion list implementation for the given HTML code. I specifically want it to expand when 'Technical' is clicked, and collapse upon clicking again. Here is the HTML code: <!-- Techincal --> <div class= ...

Tips for connecting a webpage from a specific date

Is it possible to create a link using a date picker for a specific date, such as today's date being 25/2/2015? If something is updated on a page and someone clicks on that date (e.g. 25/2/2015) in the future, how would they be able to view that page? ...

Restricting choices once user selects an option (HTML)

Currently, I am faced with a dilemma regarding two sets of options for an HTML form. One set consists of various units (such as cm, in, ft.), while the other set includes different locations. The selection of a unit would restrict certain location option ...

When using selenium with python, the function excecute_script('return variable') may not technically return variables, even though the variable does exist

My attempt to retrieve a variable from javascript code using selenium is encountering difficulties. Despite the presence of the variable (confirmed by inspecting the source code before executing the script), the command driver.execute_script('return v ...

Browser does not support the Media Query

I'm completely puzzled by Media Queries. I've been attempting to resolve this issue but cannot seem to identify where the problem lies. While creating a website with Wordpress, my header.php contains the following line: <meta name="viewpo ...

Compatibility issues with jQuery observed in Firefox and Internet Explorer 11

Check out the code here: jsfiddle demo HTML CODE: <div class="first"> <!-- Part one --> <div class="acord_col"> <div class="img_class" id="exist_site"></div> <div class="intro_text"> </div> </div&g ...