【问题标题】:Reload in jQuery BootGrid not work在 jQuery BootGrid 中重新加载不起作用
【发布时间】:2023-03-23 01:00:01
【问题描述】:

我在 bootgrid 中重新加载 ajax 数据时遇到问题 (http://www.jquery-bootgrid.com/)

我已经成功准备好要显示的网格,但是如果我将项目添加到数据库,我想重新加载网格。

我的代码现在是这样的(缩短的):

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

所以网格变量是全局变量,可以从任何地方访问。 但此处记录了函数重载:http://www.jquery-bootgrid.com/Documentation#methods 不起作用,我将 ajax 参数设置为 true

有什么建议吗?

感谢和抱歉我的英语

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    你试过了吗:

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

    对我来说,ajax 请求已加载

    【讨论】:

    • 谢谢你,迈克尔。你是救生员。为我节省了很多搜索工作:)
    • 页面不保留。
    【解决方案2】:

    所以我自己完成了这项任务:-)

    我不使用grid.reload()方法,但是ajax保存后,调用方便:

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

    【讨论】:

      【解决方案3】:

      在脚本jquery.bootgrid.js片段中更改以下内容

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

      改为:

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

      【讨论】:

        猜你喜欢
        • 2015-11-11
        • 2018-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多