skip to Main Content

Why can’t i use bootstrap editable table in this way?

<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>


    //put data in js variable and fill 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 thread gets highlighted, additional element (input field) not being created.
Thanks

2

Answers


  1. You missed the ready function, due to this jquery is not able to bind the data.

    //put data in js variable and fill 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'
            });
    });
    

    by running the script in console it worked for me

    Login or Signup to reply.
  2. try and add delay on load, should fix it:

    setTimeout(function(){
                $.fn.editable.defaults.mode = 'inline';
                var a = $('a');
                $('a').editable({
                    type: 'text',
                    pk: 1,
                    name: 'parket',
                    title: 'Enter username'
                });
                $('td').editable({
                    type: 'text',
                    pk: 1,
                    name: 'parket',
                    title: 'Enter username'
                });
            },500);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search