Editable JSON data within a table using Twitter Bootstrap

How come I am unable to utilize the bootstrap editable table in this manner?

<table id="addElements" data-height="299">
    <thead>
        <tr>
            <th data-field="id" data-align="right">Item ID</th>
            <th data-field="element" data-align="center">Element</th>
            <th data-field="weight" data-align="">Težina</th>
            <th data-field="default_thickness" data-align="">Debljina</th>
        </tr>
    </thead>
</table>


    //store data in a JavaScript variable and populate the table
var elementData = [{
    "id": "1",
    "element": "c",
    "weight": "20",
    "default_thickness": "6"
}, {
    "id": "2",
    "element": "k",
    "weight": "21",
    "default_thickness": "2"
}, {
    "id": "3",
    "element": "p",
    "weight": "18",
    "default_thickness": "2"
}];
$(function () {
    $('#addElements').bootstrapTable({
        data: elementData
    });
})

$.fn.editable.defaults.mode = 'inline';
    $('td').editable({
            url: '/post',
            type: 'text',
            pk: 1,
            name: 'parket',
            title: 'Enter username'
        });

In this fiddle https://jsfiddle.net/aleksacavic/03agu1ex/1/ it works, when clicked, table cells are in edit mode. But identical code on my site is not working? What am i missing? As I can see, on my side, when clicked, cells are not allowed to change class, only table header gets highlighted, additional element (input field) not being created. Thanks

Answer №1

Ensure you include the ready function, as without it jQuery will not be able to bind the data properly.

//store data in a JavaScript variable and populate the table
$(window).bind("load", function() {
    var elementData = [{
        "id": "1",
        "element": "c",
        "weight": "20",
        "default_thickness": "6"
    }, {
        "id": "2",
        "element": "k",
        "weight": "21",
        "default_thickness": "2"
    }, {
        "id": "3",
        "element": "p",
        "weight": "18",
        "default_thickness": "2"
    }];
    $(function () {
        $('#addElements').bootstrapTable({
            data: elementData
        });
    })


$.fn.editable.defaults.mode = 'inline';
        $('a').editable({
            url: '/post',
            type: 'text',
            pk: 1,
            name: 'parket',
            title: 'Enter username'
        });
    $('td').editable({
            url: '/post',
            type: 'text',
            pk: 1,
            name: 'parket',
            title: 'Enter username'
        });
});

https://i.sstatic.net/i6Dmm.png

Answer №2

Adding a delay upon loading might solve the issue:

setTimeout(function(){
            $.fn.editable.defaults.mode = 'inline';
            var links = $('a');
            $('a').editable({
                type: 'text',
                pk: 1,
                name: 'parket',
                title: 'Enter username'
            });
            $('td').editable({
                type: 'text',
                pk: 1,
                name: 'parket',
                title: 'Enter username'
            });
        },500);

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 sendKeys() method is malfunctioning in Selenium WebDriver

When attempting to enter phone numbers into the designated field, an error is being encountered. Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element The following code snippet is involved: driver.get("https://m ...

Unusual actions exhibited by a combination of JavaScript functions

Encountering an issue with a JavaScript file containing multiple functions causing strange behavior. The Logging.js file is responsible for writing to a text file: function WriteLog(message) { var fso = new ActiveXObject("Scripting.FileSystemObject") ...

Printing Strings in JavaScript IF Conditional Block

Hello there! I am looking for assistance with a JavaScript concept. Recently, I created some code where in the HTML file, there is a div element with an id of "GetID" where the string outputs are meant to be displayed. The JavaScript code looks something ...

jquery combobox with overlapping autocomplete suggestions

Encountering an issue with the jquery autocomplete combobox where they overlap when positioned side by side. Referencing this link for guidance: http://jqueryui.com/autocomplete/#combobox <!doctype html> <html lang="en"> <head> <me ...

Choose an element for styling only if it contains a child element with a particular class

Looking to adjust padding based on specific child class <div class="container page-content"> </div> The page-content class typically includes padding: .container.page-content{ padding-top: 160px; } However, there is a special case wher ...

Changing the border color of material ui Rating stars: A guide

I am struggling to change the border color of stars in Material UI Rating because my background color is black, making it difficult to see when the star is empty! Here's the code snippet: import Rating from '@material-ui/lab/Rating'; import ...

Incorrect data retrieval from JSON object with JQUERY

I am working on a function that extracts data from a database on the server-side and assigns it as the value of a textbox on the client-side. The function is functioning correctly on the server-side, but on the client-side, when I use console.log to view t ...

Should we combine social icons into a sprite image, or keep them separate?

Currently in the process of developing an HTML/CSS template, with plans to incorporate social media icons from the following source: These icons are available as 41 individual .png files. The goal is to integrate them into the template using CSS classes f ...

Tips for ensuring only one submenu is open at a time

I have successfully created a responsive menu that is working well. However, I am facing an issue. I want only one menu to be open at a time. When a submenu is opened, the other menus should be hidden. How can I achieve this? Below is my Script code $( ...

Arranging Columns in JQuery Sortable and Bootstrap Causes Item to Disappear from the First to Last Column

Currently experimenting with integrating JQuery Sortable with Bootstrap v3. My layout consists of 3 columns, where I aim to drag and drop items from column 1 to column 3, with column 2 hosting buttons for bidirectional movement. Despite the functionality ...

Utilizing the JavaScript map method to structure API response data

Here is the JSON data I have: { "result": [{ "name": "a", "value": 20, "max": 100, "sale_value": [{ "no": 1, "name": "aaaaa", "price": 200 }, { "no": 2, ...

Adjust webpage display with JavaScript

Utilizing the mobile-first approach of Zurb Foundation, I successfully created a responsive design. However, my client now requires a direct link labeled "View desktop version" in the footer for when the website is accessed on mobile devices or tablets. T ...

Is there a way to verify if the password entered by the user matches the input provided in the old password field?

I am trying to compare the user's password with the one entered in the "oldPassword" input field. The challenge is hashing the input from the "oldPassword" field for comparison. How can I achieve this? Please review my ejs file and suggest improvement ...

Encountering an issue while attempting to retrieve data from an API with JSON and AJAX

I've been attempting to retrieve data from an API using AJAX and JSON, but I keep encountering this error message: ReferenceError: Can't find variable: $ Global code Here is the HTML code that was utilized: <!DOCTYPE html PUBLIC "-//W3C/ ...

The code within $(document).ready() isn't fully prepared

Feeling frustrated after spending hours searching and attempting to refactor one of my old modules on a rendered Mustache template. It's like diving into code chaos. <section id="slideShow"> <script id="slideShow-template" type="text/tem ...

Tips on incorporating toggle css classes on an element with a click event?

When working with Angular typescript instead of $scope, I am having trouble finding examples that don't involve $scope or JQuery. My goal is to create a clickable ellipsis that, when clicked, removes the overflow and text-overflow properties of a spec ...

How come my audio element in HTML refuses to play once I adjust its volume setting?

I'm currently working through a React tutorial and I've encountered an issue with my component. I have implemented an audio HTML tag in the component, with its volume controlled by an input from another React component. However, despite setting u ...

problem encountered while using jquery toggle to open/close elements

I am working on a small private messaging system where users can toggle messages open or close using buttons. When no message is open, the button displays 'lesen'. Upon clicking the button, the message opens and the text changes to 'schließ ...

Breaking free of the constraints of a 100% height container, UL escapes its

In both Chrome and Firefox, UL list items do not seem to adhere to the parent container's width of 100%. I attempted to use list-style-position: inside;, but unfortunately, that did not solve the issue: <html style="height: 100%"> <body styl ...

Creating a fairness algorithm with circular arrays in Javascript: A step-by-step guide

My child's baseball team consists of 13 players. In order to ensure that each player has an equal opportunity to play different positions, I devised a JavaScript algorithm. However, the current algorithm does not seem to be distributing the positions ...