如何检测页面上的所有jqGrids是否都已加载?

编程入门 行业动态 更新时间:2024-10-07 14:33:07
本文介绍了如何检测页面上的所有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是否都已加载?

本文发布于:2023-11-26 21:50:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635332.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:都已   加载   页面   jqGrids

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!