What is the best way to add a new row to the body of an HTML tablesorter table using javascript or

Within my company, I have designed a functional testing tool for our application using a combination of HTML, CSS, JavaScript, Node.js, Express, and Tablesorter. The test tool has been able to successfully execute various function tests.

The styling of my table is sourced from an open-source project called 'Tablesorter'.

https://i.sstatic.net/f8rBe.jpg

This particular segment serves as the edit screen, stored in .ejs format. Hence, the Node.js server dynamically renders this file into HTML.

However, I am facing challenges when attempting to add rows to the table. In search of a solution, I discovered the following approach:


                for (var i in rList) {
                    var table = document.getElementById("ID_Table");
                    var row = table.insertRow(-1);
                    var cell1 = row.insertCell(-1);
                    var cell2 = row.insertCell(-1);
                    var list = rList[i].split(" ");
                    cell1.innerHTML = list[0];
                    cell2.innerHTML = list[1];
                }
            

Unfortunately, this method falls short. The additional rows do not adhere to the 'tablesorter' style which poses a dilemma on how to resolve this issue.

https://i.sstatic.net/fiIqR.jpg

The applied 'tablesorter' style fails to encompass newly added rows, leaving me puzzled on the possible solutions.


                <!-- Your customized HTML content goes here -->
            

This section showcases my personal .ejs File.

Further, presented below is the printResult Function found within indexCore.js:


                function printResult(){
                    var rList = resultList.split('\n');
                    
                    for (var i in rList) {
                        var table = document.getElementById("ID_Table");
                        var row = table.insertRow(-1);
                        var cell1 = row.insertCell(0);
                        var cell2 = row.insertCell(1);
                        var list = rList[i].split(" ");
                        cell1.innerHTML = list[0];
                        cell2.innerHTML = list[1];
                    }
                }
            

Answer №1

If you find that your client side solution is running after the table has been initialized by Tablesorter, you can edit and apply your logic directly in the .ejs file on your backend. Another option is to try implementing your client side solution by adding the rows to the table first and then initializing Tablesorter. Best of luck!

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

The auto-fill feature in typehead.js is not functioning correctly for predictions

Trying to implement an autocomplete field using typehead.js () : $(document).ready(function() { var result; var result = new Bloodhound({ datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.Domain.domain); ...

Do [(ngModel)] bindings strictly adhere to being strings?

Imagine a scenario where you have a radiobutton HTML element within an angular application, <div class="radio"> <label> <input type="radio" name="approvedeny" value="true" [(ngModel)]=_approvedOrDenied> Approve < ...

I'm facing an issue where I am unable to access an element by its ID in a c++ application, despite everything else functioning correctly

I am currently working on some HTML, CSS, and JS tasks and I have encountered a problem. For some reason, I am unable to access elements in JavaScript using getElementById or jQuery tags... nothing seems to work. Here is the HTML code for my element: < ...

Tips for positioning buttons using HTML and CSS

Looking for some help with my HTML page design. I have a few buttons that I want to style like this: https://i.stack.imgur.com/3UArn.png I'm struggling with CSS and can't seem to get them positioned correctly. Currently, they are displaying "bel ...

Integrating a JSON file with Node.js to efficiently sort data

I am completely new to using json with nodejs and ejs, so please excuse my lack of expertise. Despite being able to generate a list of items from the json file, I'm encountering an issue when trying to sort them using a drop-down menu. Instead of disp ...

Should the text underneath the image be placed above the rest of the images?

In the process of developing my game, I encountered a challenge where text needs to be dragged under specific images. To achieve this, I envision creating tabs below the images for the text to be dragged onto. My initial approach involved wrapping each im ...

What is the best way to incorporate the same partial multiple times with varying content in Nunjucks?

I'm working on several page templates that require the same partial to be included multiple times but with different content each time. I explored looping this, but the order might not always be sequential. Here's an example of how my page templ ...

Guidelines for displaying JSON data in HTML <ul><li></li></ul> format using jQuery within an ASP.NET environment

I am currently developing an asp.net application that involves fetching data from a database in JSON format and displaying it within html ul-li tags using jQuery. Below is a snippet of my Html Page: <html xmlns="http://www.w3.org/1999/xhtml"> <he ...

Prevent the bootstrap collapse hide feature from functioning when content is already visible or expanded

I have a simple question. I would like to utilize the Bootstrap 3 collapse function to display some content, but without the ability to hide it when clicking on the link or button. Basically, I want the content to appear when clicking on the link or butto ...

Having trouble figuring out how to sort an object array within a Vuex action in Vue.js

Currently attempting to sort an array, however, the sorting function doesn't seem to be working as expected based on the console log output. I'm puzzled as to why it's not executing properly. Interestingly, the same code runs fine in simple ...

Identifying Ctrl+V in VueJS: A Guide

Although I found the answers to this question, they were for jQuery and not suitable for my needs with vue.js. Currently, I have successfully implemented code to detect single character presses: export default { name: 'game', data () { ...

How can I send data to a Python script from a web application?

I have a Python script that requires 6 parameters to run, provided through the command line. python_file.py param1, param2, param3, param4, param5, param6 My goal is to pass these parameters from a web application built with Flask and Bootstrap. I want e ...

Checking authentication globally using Vue.js

In the main blade file, I have the following code snippet: <script> window.App = {!! json_encode([ 'csrfToken' => csrf_token(), 'user' => Auth::user(), 'signedIn' => Auth::check() ...

`Vue component event handler testing done right`

I have a component containing an anchor tag with an associated handler, onSelectLink(). <a :href="$t('footer.termsUrl')" target="_blank" name="termsAndConditions" @click="onSelectLink($event.target.name)">{{ $t('terms') } ...

Ensure portrait orientation images have a restricted width to maintain their aspect ratio

On a responsive site, I have set up flexslider to showcase both landscape and portrait orientation images. The smoothHeight: true option is enabled to adjust the height according to the images. However, at the largest media query where the flexslider cont ...

Is there a way to destructure {this.props.children}?

How can I add a background to my mobile app using "this.props.children" without receiving an ESLint error saying "Must use destructuring props assignment"? Why am I unable to destructure these props? Here is my code: export default class WallPaper exte ...

Disappearing Act: The Vanishing React.js Dialog Component that Lurks

Currently, I am utilizing a Dialog component from Material-UI and, overall, it is functioning correctly. However, there is an issue where if I click away from the Dialog, it disappears as expected, but occasionally it remains in the DOM with an opacity of ...

What is the most efficient method for storing and organizing IP addresses in a MongoDB database?

I have been searching for various Q&A on ways to efficiently save and sort IPs in a mongo db, but I am struggling to find a solution. Firstly: how should I save an IP address? As a string? Integer? Something else? Secondly: Once saved (let's say ...

Using jQuery to Create Printable Forms

Hello everyone, I have the following HTML/PHP code on my webpage: if(isset($_GET['user_id']) && $_SESSION['role']=="admin"){ $user_id = $_GET['user_id']; }else{ $user_id = $_SESSION['user_id']; } ?> <b ...

Using MongoDB Object as middleware in Express applications

I’m facing issues trying to access the "DB" database object that gets created when the MongoDB client module establishes a connection with my MongoDB database. Currently, I am encountering an error indicating that in data.js, 'db' is not defin ...