Search code examples
javascriptjquerypopover

Bootstrap popover doesn't work in object


I am trying to make my own js class for table grid adjustments(hide columns) and my popover button doesn't work.

When i use all of that functions on page it works, but when I put in prototype it fails.

here is my grid.js:

function Grid(element, tableId, module){
    return this.init(element, tableId, module);
};

Grid.prototype = {

    grid: [],

    element: "",

    popover: null,

    tableId: "",

    module: "",

    backEndURL: location.href,

    formId: "#grid_form",

    wrapper: "#grid_entities",

    init: function(element, tableId, module){

            this.element = element;
            this.tableId = tableId;
            this.module = module;

            this.initButton();
            this.addOnClickListner();


    },

    initButton: function(){

        this.popover = $(this.element).popover({
            placement: "bottom",
            html: true,
            content: this.getPopoverContent()
        });

    },
...

Index.php:

<div id="filterButtons">
    <i class="left iconfilter" id="filterButton" data-toggle="popover"></i>
    <i class="left iconlayout" id="gridButton" data-toggle="popover"></i>
</div>
...
<script>
$(document).ready(function () {
    var grid = new Grid(...);
});
</script>

Also Grid.js is included in the bottom of the page.


Solution

  • Thanks to all. I solve it. The reason was that I generate popover content via ajax:

    initButton: function(){
    
        this.popover = $(this.element).popover({
            placement: "bottom",
            html: true,
            trigger: 'click',
            content: this.popoverContent
        });
    
    },
    

    popoverContent() was a ajax request to server side.