0

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?

RemarkLima
  • 11,639
  • 7
  • 37
  • 56

1 Answers1

3

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • As a suggestion, if you will call the global function `Load_Complete` from inside the anonymous function binded to "jqGridLoadComplete", I'd suggest that the counter is decremented inside the anonymous function and the global function is called only once when the counter is 0. In other words, you could have a function `All_Load_Complete`. If the number of function calls is lower it will have a positive impact on speed (e.g. seen in http://www.slideshare.net/madrobby/extreme-javascript-performance slides 13-18). –  Feb 13 '14 at 12:31
  • @Tom: Sorry, but I can't follow you. What "`All_Load_Complete` function" you mean? What I suggested is decrementing of the counter inside of `"jqGridLoadComplete"` event handler. So what is your suggestion? – Oleg Feb 13 '14 at 12:39
  • That must be my bad. I thought that you were suggesting to decrement the counter in the global function reading the third bullet point in your answer. –  Feb 13 '14 at 13:04
  • I like the thinking of counting down... I've been trying to check for the loading div being visible etc... Thank you again, I'll let you know how I get on – RemarkLima Feb 13 '14 at 13:36
  • @Tom: It was probable misunderstanding because I used the word `"global"`. I used the word quoted because one need just to have *one* callback or event handler which will be called from every grid on the page. In any way it's good that the problem is solved now. – Oleg Feb 13 '14 at 14:13