如何检测页面上的所有jqGrids是否都已加载? [英] How to detect if all jqGrids on a page have loaded?

查看:544
本文介绍了如何检测页面上的所有jqGrids是否都已加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqGrid的ASP.NET WebForms版本,但是我确定应该将相同的事件用作标准网格.

我有一些页面上有多个网格,可能只是一个页面,也可能是多个页面.我有一个打印按钮,它将显示10,000条记录(以显示网格上的所有记录),将其调整大小以适合A4纸,然后按下window.print(),然后返回到原始记录数,然后将网格重新调整为100%.

缺少的部分是知道什么时候触发window.print(),因为我需要等待所有网格加载后才能这样做.

我尝试使用全局var allGridsLoaded = false;,然后使用Load_Complete事件和beforePageChange来设置var,但是显然每个网格都重置了var,我不确定如何跟踪它们吗? /p>

Load_Complete中,我想我可以遍历每个网格,但是最清楚的方法是判断它们是否已加载?

解决方案

我不确定我是否完全了解您的要求.尽管如此,在我看来您仍然需要

  • 获取页面上的网格总数
  • 为所有网格注册全局" Load_Complete
  • 在开始准备打印之前,将计数器设置为网格总数,开始重新加载网格,将全局" Load_Complete手柄内的计数器递减,如果计数器的值为0,则递减window.print().

因此,您真正需要的是上述列表中的第一件事.每个网格都将基于一个空的<table>元素构建. jqGrid将"ui-jqgrid-btable"类添加到所有表.所以你可以使用

 $(".ui-jqgrid-btable")
 

获取页面上所有网格的jQuery包装. $(".ui-jqgrid-btable").length是网格数.要为所有网格注册通用的全局" Load_Complete,可以使用jqGridLoadComplete(或jqGridAfterLoadComplete)事件(请参见 $(".ui-jqgrid-btable").bind("jqGridLoadComplete", function (e, data) { // ... });

有关其他信息,请参见答案.

我希望您能够以这种方式实现所有要求.

I'm using the ASP.NET WebForms version of jqGrid, however I'm sure the same events should be available as the standard grid.

I have some pages with multiple grids on them, it could be just one, or could be several. I have a print button which will display 10,000 records (to display all the records on the grid), resize it to fit onto an A4 sheet, fire window.print() and then go back to the original record count, and resize the grid back to 100%.

The missing part is to know when to fire window.print() as I need to wait for all the grids to be loaded before doing so.

I've tried having a global var allGridsLoaded = false; and then use the Load_Complete event and beforePageChange to set the var, but obviously with each grid resetting the var I'm not sure how to track them all?

In the Load_Complete I'm thinking I could loop through each grid, but what's the cleanest way to tell if they've loaded?

解决方案

I'm not sure that I full understand your requirements. Nevertheless it seems to me that you need

  • get the total number of grids on the page
  • register "global" Load_Complete for all grids
  • set the counter to the total number of grids before starting preparing for printing, start reload the grids, decrements the counter inside of "global" Load_Complete handle and window.print() if the counter will have the value 0.

So what you really need are two first things from the above list. Every grid will be build based on an empty <table> element. jqGrid adds "ui-jqgrid-btable" class to all the tables. So you can use

$(".ui-jqgrid-btable")

to get jQuery wrapper to all grids on the page. $(".ui-jqgrid-btable").length is the number of grids. To register common "global" Load_Complete for all grids you can use jqGridLoadComplete (or jqGridAfterLoadComplete) event (see the documentation):

$(".ui-jqgrid-btable").bind("jqGridLoadComplete", function (e, data) {
    // ...
});

See the answer for additional information.

I hope you will be able to implement all your requirements in the way.

这篇关于如何检测页面上的所有jqGrids是否都已加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆