【问题标题】:jqgrid afterShowForm not being calledjqgrid afterShowForm 没有被调用
【发布时间】:2011-07-21 19:39:25
【问题描述】:

我想将 jqgrid 的视图形式定位到屏幕的中心。因为高度是自动设置的(取决于数据量),所以我需要在渲染后计算它的中心位置。因此我想使用 afterShowForm。不幸的是,它没有被称为任何东西。我尝试了旧版本的 jqGrid(可能最新版本包含错误),但它并没有解决我的问题。有人知道为什么它不发射吗?请注意,当我在“beforeShowForm”中更改“afterShowForm”时,它确实会被解雇。但是,高度还没有计算出来。谢谢! (当然,非常欢迎您提出另一种实现我的目标的方法!)。代码:

        $("#grid").jqGrid("navGrid", "#pager",
        { view: true, addfunc: additem, editfunc: edititem, delfunc: deleteitem },
        {},
        {},
        {},
        {},
        { width: 350,
            afterShowForm: function (formid) {
                alert('yey');
                // Here I want to center the form
            }
        }
        );

编辑:在 wiki 上,我发现 View 表单没有 afterShowForm 事件;它只有 onClose 和 beforeShowForm :( 所以我猜不可能以这种方式将位置设置为中心..

【问题讨论】:

标签: jquery jqgrid


【解决方案1】:

问题的原因很简单:查看表单中的afterShowForm真的不存在。仅支持树事件:onClose、beforeShowFormbeforeInitData。所以你应该使用beforeShowForm,但是在另一个线程中做你需要的:

beforeShowForm: function($form) {
    setTimeout(function() {
        // do here all what you need (like alert('yey');)
    },50);
}

在大多数情况下,您甚至可以使用 0(而不是 50)作为 setTimeout JavaScript 函数的第二个参数。

【讨论】:

  • 是的.. 我想这是迄今为止最好的解决方法;) 让我们只希望在不久的某个地方实现 afterShowForm。谢谢!
  • @user825887:不客气!您可以在trirand forum中提出相应的变更请求。
【解决方案2】:

好的,我就这样解决了。我正在使用第二个 setTimeout() ,否则当窗口从旧位置移动到屏幕中心时,你会得到一个“闪光”。谢谢!

var viewform = "#viewmodgrid";

        function centerViewForm() {
            $(viewform).css('visibility', 'hidden');
            setTimeout(function () {
                $(viewform).css('left', ($(document).width() / 2) - ($(viewform).width() / 2));
                $(viewform).css('top', ($(document).height() / 2) - ($(viewform).height() / 2));
                $(viewform).css('visibility', 'visible');
            });
        }

...                 beforeShowForm: function (formid) {
                    centerViewForm();
                }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    相关资源
    最近更新 更多