KesavCZ
KesavCZ

Reputation: 123

Reload in jQuery BootGrid not work

i have problem with reloading ajax data in bootgrid (http://www.jquery-bootgrid.com/)

i have successfully prepared grid to display at all, but if i add item to db, i want make reload of the grid.

my code is now this (shortened):

var grid;
$(document).ready(function() {
    grid = initGrid();
});
function initGrid() {
    var local_grid = $('#clients-grid').bootgrid({
        "ajax": true,
        "url": "/client/grid",
        "formatters": {
            "commands": function(column, row) {
                return "<button type=\"button\" class=\"btn btn-default command-edit\" data-row-id=\"" + row.id + "\"><span class=\"glyphicon glyphicon-pencil\"></span></button> " +
                        "<button type=\"button\" class=\"btn btn-default command-delete\" data-row-id=\"" + row.id + "\"><span class=\"glyphicon glyphicon-trash\"></span></button> " +
                        "<button type=\"button\" class=\"btn btn-default command-mail\" data-row-id=\"" + row.id + "\"><span class=\"glyphicon glyphicon-envelope\"></span></button>";
            },
            "tooltips": function(column,row) {
                return '<span type="button" class="content-popover" title="'+row.name+'" data-content="'+row.content+'">Najeďte myší pro zobrazení obsahu</span>';
            },
            "clientname": function(column,row) {
                return row.name;
            }
        }
    }).on("loaded.rs.jquery.bootgrid", function() {
        $('.content-popover').popover({
            trigger: 'hover',
            html: true,
            placement: 'right',
            content: $(this).attr('data-content')
        });
        grid.find(".command-edit").on("click", function(e) {
            editClient($(this).data('row-id'));
        }).end().find(".command-delete").on("click", function(e) {
            var id = $(this).data('row-id');
            if (confirm('Opravdu smazat klienta s ID: '+$(this).data("row-id")+'?')) {
                deleteClient($(this).data('row-id'));
            }
        }).end().find(".command-mail").on("click", function(e){
            mailClient($(this).data('row-id'));
        });
    });
    return local_grid;
}

so grid variable is in global and is accessible from everywhere.. but function reload documented here: http://www.jquery-bootgrid.com/Documentation#methods not working, and i have ajax parameter set on true

Any advice?

Thanks and sorry for my english

Upvotes: 7

Views: 10300

Answers (3)

Rogi
Rogi

Reputation: 1

Change the following in the script jquery.bootgrid.js fragment

   Grid.prototype.reload = function()
   {
       this.current = 1; // reset
       loadData.call(this);
       return this;
   };

change to:

Grid.prototype.reload = function(current)
{
    this.current = (current !== 'undefined') ? current : 1; 
    loadData.call(this);

    return this;
};

Upvotes: 0

Michael
Michael

Reputation: 441

Did you try:

$('#grid-data').bootgrid('reload');

For me the ajax request is loaded

Upvotes: 11

KesavCZ
KesavCZ

Reputation: 123

So i finished this task myself :-)

I do not using grid.reload() method, but after ajax save, call easily:

$('button[title=Refresh]').click();

Upvotes: 2

Related Questions