question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bootstrap tooltip not working inside table

See original GitHub issue

Hi I am using a function that I saw from one of your example which is to display action buttons. I am having a problem with the bootstrap tooltip working on these buttons.

Here is the JS:

function actionsFormatter(value, row, index) {
        if (row.id == 1 || row.id == 2) {
             return [
                '<a class="btn btn-primary btn-xs mr10" data-tooltip="true" data-placement="bottom" href="admin_permission.php?id='+row.id+'" title="Edit">',
                    '<i class="glyphicon glyphicon-pencil"></i>',
                '</a>',
                '<a class="btn btn-danger btn-xs disabled" data-tooltip="true" data-placement="bottom" href="#" title="Remove">',
                    '<i class="glyphicon glyphicon-trash"></i>',
                '</a>',
            ].join(''); 
        } else {
                return [
                    '<a class="btn btn-primary btn-xs mr10" data-tooltip="true" data-placement="bottom" href="admin_permission.php?id='+row.id+'" title="Edit">',
                        '<i class="glyphicon glyphicon-pencil"></i>',
                    '</a>',
                    '<a class="btn btn-danger btn-xs remove" data-tooltip="true" data-placement="bottom" href="#" title="Remove">',
                        '<i class="glyphicon glyphicon-trash"></i>',
                    '</a>',
                ].join('');
        }
    }
window.actionsEvents = {
        'click .remove': function (e, value, row, index) {
            // Open modal on click
            $('#deleteModal').modal();
            // Add permission names to modal
            $('#permission-name').text('Are you sure you want to delete: ' + row.name + '?');
            // Create a hidden input to use when submitting form
            var input = document.createElement("input");
            input.setAttribute('type', 'hidden');           
            input.setAttribute('name', 'delete['+row.id+']');
            input.setAttribute("id", 'delete['+row.id+']');            
            input.setAttribute('value', row.id);         
            //append to form element that you want .
            document.getElementById("deleteModalForm").appendChild(input);  

            console.log(value, row, index);
        }
    };

And the I have this to activate the tooltips:

$('[data-tooltip="true"]').tooltip({
        container: 'body'
    });

The tooltip works fine on the toolbar, but does not work for these buttons. Can you see why this doesn’t work? Here is a JSFiddle. Notice that the top let button has the bootstrap tooltip, but the action buttons in the table does not work.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
vletouxcommented, Apr 21, 2022

I had also the same problem but I don’t think is the best answer. I started as suggested to add code for the event post-body.bs.table but not all events were covered. Then I added the code suggested above with the click handler. But my tooltip is on a column (a question mark item) and when clicking on it, the tooltip does not disappear.

After some time, I think the best is to use the “selector” feature. See https://getbootstrap.com/docs/5.0/components/tooltips/#options

instead of adding data-bs-tooltip to tooltips, the best is to add a new class (like has-tooltip) and to use the following js:

new bootstrap.Tooltip(document.body, {
        selector: '.has-tooltip'
    });

Automatically created and destroyed tooltip are handled automatically. No additional code is needed.

3reactions
wenzhixincommented, Feb 28, 2015

You need to active the tooltip after table body is rendered: http://jsfiddle.net/e3nk137y/791/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Bootstrap Tooltip not work correctly when placed ...
Tooltip inserts a div after the specified dom element. In your case, the div is inserted between TDs, which messes with the render...
Read more >
Bootstrap Tooltip doesn't not work in childrow - DataTables
I knos this font awesome pb is not link to data table but I have no idea . It works if I use...
Read more >
Tooltips · Bootstrap v5.0
Triggering tooltips on hidden elements will not work. Tooltips for .disabled or disabled elements must be triggered on a wrapper element.
Read more >
Can&#38;#039;t use tooltip for buttons inside datatables
Expected behavior using the render. · Actual behavior tooltip will appear for a second until user moves mouse, then once is it is...
Read more >
Bootstrap Tooltip Table - Visual LightBox
When you have activated the tooltips functionality just to assign a tooltip to an element you must bring in two mandatory and just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found