How to detect if all jqGrids on a page have loaded

2019-09-07 00:01发布

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?

1条回答
戒情不戒烟
2楼-- · 2019-09-07 00:41

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.

查看更多
登录 后发表回答