Encountering a TypeError with DataTables and Tabledit

I've been attempting to integrate DataTables with Tabledit, but I keep encountering the error message "TypeError: Cannot set properties of undefined (setting 'nTf')". The number of tags also matches up.

Interestingly, if I comment out the "editable" object, the error disappears. However, this part is essential for the library as it allows only those columns to be editable.

<html>
                
<head>
    <title>Person Information</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://markcell.github.io/jquery-tabledit/assets/js/tabledit.min.js"></script>
    <script>
        $(document).ready(function () {
            var baseurl = "https://run.mocky.io/v3/391adcbb-160c-4111-b853-2e273700676b";
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", baseurl, true);
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var persons = JSON.parse(xmlhttp.responseText);

                    $.fn.dataTable.ext.errMode = 'none';
                    $("#example").DataTable({
                        data: persons,
                        "columns": [{
                                "data": "id"
                            },
                            {
                                "data": "username"
                            },
                            {
                                "data": "email"
                            },

                            {
                                "data": "avatar"
                            }
                        ]
                    });
                }
            };
            xmlhttp.send();

        
                $('#example').Tabledit({
                    url: 'action.php',
                    dataType: 'json',
                    eventType: 'dblclick',
                    editButton: false,
                    columns: {
                        identifier: [0, 'id'],
                        editable: [
                            [1, 'username'],
                            [2, 'email']
                            
                        ]
                    }
                });

        });
    </script>
</head>

<body>

    <div class="container">

    </div>
    <div class="container">

        <table id="example" style="width:100%">
            <thead>
                <tr>
                    <th>id</th>
                    <th>username</th>
                    <th>email</th>
                    <th>avatar</th>


                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>id</th>
                    <th>username</th>
                    <th>email</th>
                    <th>avatar</th>


                </tr>
            </tfoot>
        </table>
    </div>
</body>

</html>                 

Answer №1

To enhance the way your DataTable retrieves its Ajax data, you can utilize DataTables' built-in support for Ajax calls.

Subsequently, you can integrate Tabledit functionality into the resultant DataTable by leveraging the initComplete option.

$(document).ready(function() {
    var baseurl = "https://run.mocky.io/v3/391adcbb-160c-4111-b853-2e273700676b";

    $("#example").DataTable({
        ajax: {
            url: baseurl,
            dataSrc: ""
        },
        columns: [{
                data: "id"
            },
            {
                data: "username"
            },
            {
                data: "email"
            },

            {
                data: "avatar"
            }
        ],
        initComplete: function(settings, json) {

            $('#example').Tabledit({
                //url: 'action.php',
                dataType: 'json',
                eventType: 'dblclick',
                editButton: false,
                columns: {
                    identifier: [0, 'id'],
                    editable: [
                        [1, 'username'],
                        [2, 'email']

                    ]
                }
            });

        }
    });

});
<html>
    <head>
        <title>Person Information</title>
        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
        <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <script src="https://markcell.github.io/jquery-tabledit/assets/js/tabledit.min.js"></script>
    </head>
    <body>
        <div class="container">
        </div>
        <div class="container">
            <table id="example" style="width:100%">
                <thead>
                    <tr>
                        <th>id</th>
                        <th>username</th>
                        <th>email</th>
                        <th>avatar</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th>id</th>
                        <th>username</th>
                        <th>email</th>
                        <th>avatar</th>
                    </tr>
                </tfoot>
            </table>
        </div>
    </body>
</html>

Upon running the provided code snippet and double-clicking on a value within the username or email columns, the respective cell will transition into an editable state.

Note - The action.php setting has been commented out due to its unavailability. Consequently, any edits made are not transmitted or stored anywhere.

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

Incorporating TinyMCE into numerous dynamically generated text areas

I am facing an issue with dynamically created textareas. The content in these textareas is generated dynamically. This is how I retrieve the data and create the textareas dynamically: $(document).ready(function(){ $('#btn').click(function(){ ...

Arrangement of Bootstrap card components

Each card contains dynamic content fetched from the backend. <div *ngFor="let cardData of dataArray"> <div class="card-header"> <div [innerHtml]="cardData.headerContent"></div> </div> <d ...

How to Effortlessly Submit a Form in a jQuery Mobile Website Using MVC

I have spent the entire day searching for a solution to this problem, hoping that it would be a straightforward task. My code successfully populates a dropdown box from a database. The dropdown is working and the form automatically submits after an articl ...

When the user clicks on the login text field or password field, any existing text will

Currently, I am working on the login section of my website and I would like to implement a similar effect to Twitter's login form, where the Username and Password values disappear when the Textfield and Password field are in focus. I have attempted to ...

Interfacing Highcharts with Angular for seamless data binding across series

I am fairly new to using highcharts and I am having difficulty binding my data into the series parameter. In my controller, I have an array of objects that I want to display (when I use console.log, I can see that they are all properly there) this.plotDa ...

Utilize Laravel to trigger a route action based on a dropdown selection change, generating a unique URL

In my code, I have a dropdown select containing the list of the next 12 months: <select name="month" id="specificMonth"> @foreach(Carbon\CarbonPeriod::create(now()->startOfMonth(), '1 month', now()->addMon ...

The regular expression should consist of just letters and a single dot

Currently, I am working on creating a regular expression that allows only letters and one dot. However, there is a specific rule to follow: the dot cannot be located at the beginning or end of the string. For example: abc.difference This is what I attem ...

Using the debug module, we're able to set up debugging for our Express application with the specific tag "express-locallibrary-tutorial:server". I am curious to understand the purpose and significance of this setup

I've been diving into backend development with Express lately. I decided to work on the express-locallibrary-tutorial project from GitHub. However, I'm having trouble grasping something. var debug = require('debug')('express-locall ...

The new data is not being fetched before *ngFor is updating

In the process of developing a "Meeting List" feature that allows users to create new meetings and join existing ones. My technology stack includes: FrontEnd: Angular API: Firebase Cloud Functions DB: Firebase realtime DB To display the list of meeting ...

My code fails to recognize the top property when the window size is 1300px

Error at the Top Not Being Recognized: Hello, I am facing an issue where the top part of the webpage does not behave correctly when the window size is less than 1300px. The condition set for 100% top only applies after refreshing the page; otherwise, it d ...

Modify the color of the active class in Bootstrap

I am trying to modify the color of the active class in my HTML code as I create a nav sidebar. Here is the snippet from my code: <div class="col-sm-2"> <ul class="nav nav-pills nav-stacked nav-static"> <!--stacked for vertic ...

Angular: Struggling with Parent Component not recognizing changes in Child Component

Currently, I am facing an issue with my shopping cart functionality. When the website first loads and a user does not have a saved shopping cart, they need to click "add to cart" before one is created. The problem lies in the fact that my app.component doe ...

What steps should I follow to ensure that the processData function waits for the data returned by the getData function in Angular?

After calling the getData function, each object is stored in an array and returned. Now I need the processData function to await these results from getData and then further process them. However, when I try to console.log(cleaningData), I don't see an ...

What are the steps to implement the jQuery slide menu effect on a website?

When visiting the website , you may notice a symbol positioned in the top left corner of the site. By clicking on this symbol, a sleek div will slide out. How can this type of animation be achieved through javascript or jquery? ...

Is it possible to detect a specific string being typed by the user in jQuery?

Similar to the way Facebook reacts when you mention a username by typing @username, how can jQuery be used to set up an event listener for [text:1]? I aim to trigger an event when the user types in [text: into a text field. ...

What is the best way to add a value to the value attribute of a div using JavaScript?

Is there a way to insert a value into the value attribute of a div using Internet Explorer 9? I have attempted various JavaScript functions, but so far I can only modify the content inside the div and not the value attribute itself. <div id="mydiv" val ...

What is the best way to prioritize a non-submit button over a submit button in material-ui?

I am facing an issue with a form on my website. Whenever I press the enter key, the form is automatically submitted. Everything seems to be working fine so far. However, there is a specific scenario where if a user selects a certain option in the form, it ...

Is it possible for Angular2 to map a lone JSON object?

Dealing with a JSON response that is a single object, rather than an array, can be tricky. Recently in my project, I encountered a situation where I needed to map and use such a response from an API to fill out a template. It seemed like a simple task at f ...

Having trouble creating a unit test for exporting to CSV in Angular

Attempting to create a unit test case for the export-to-csv library within an Angular project. Encountering an error where generateCsv is not being called. Despite seeing the code executed in the coverage report, the function is not triggered. Below is the ...

Display the date that is 3 days after the selected date from the Date Picker in the text field

This is the date picker code I am currently using: var d = new Date(); $(function () { $("#datepicker").datepicker({ minDate: d, dateFormat: 'mm-dd-yy' }); }); I want to enhance this functionality so that when a date is ...