2

This post covers what I need to do: Use of local datatype to prevent grid load; however when I do this at $(document).ready(), the grid loads itself but the data then displays blank rows. (I notice that the number of rows returned is correct for the ajax call).

I've also tried specifying the model's BeforeAjaxRequest to set datatype:'local', but this doesn't happen in time to prevent the call either.

How can I stop the first grid load of a jqGrid declared in an MVC view?

Community
  • 1
  • 1
sympatric greg
  • 2,969
  • 2
  • 24
  • 29

2 Answers2

3

Trirand has modified jqGrid so that if you wire up a BeforeAjaxRequest function and have that function return false, the request is not sent.

This resolves the problem nicely.

sympatric greg
  • 2,969
  • 2
  • 24
  • 29
0

If I understand you correct you want that the empty grid will not displayed at the page load. You can do this in at leas two ways:

  • You can don't create the grid from the <table> and the optional pager <div> elements. So you can call $("#list").jqGrid({/*jqGrid parameters*/}); only if you want display the grid (at least as empty).
  • You can place <table> and the optional pager <div> elements in another container div which are hidden (<div id="mycontainer" style="display:none">...</div>) and make it visible ($("#mycontainer").show()) only if you want to show the grid.
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi Oleg, thanks for responding to the post. I'm putting my grid in the view like this:<%= Html.Trirand().JQGrid(Model.ExceptionGrid, "JQGrid1") %>. Quite simply, I don't want the grid to populate itself until I can set the postData to call a saved search/filter. – sympatric greg Jun 16 '11 at 21:23
  • @sympatric greg: Sorry, but I don't know the commercial version of jqGrid. Nevertheless I suppose, that if you place `<%= Html.Trirand().JQGrid(Model.ExceptionGrid, "JQGrid1") %>` inside of hidden div (the second way) it could solve your problem. You can make the grid visible at the same time when you change the `datatype` to 'json' and reload the grid. – Oleg Jun 16 '11 at 21:31
  • @Oleg: My objective is to not make an unnecessary call. setting the datatype doesn't stop the call. I think this is because of MVC. Maybe I ought to take it up with Tony. – sympatric greg Jun 16 '11 at 21:34
  • @sympatric greg: I don't understand which call you mean. If you set `datatype:'local'` no Ajax request to the server to fill the grid contain will be made. – Oleg Jun 16 '11 at 21:47
  • @Oleg: as far as I can tell, there is no way of setting datatype:'local' before the ajax call is initiated. – sympatric greg Jun 16 '11 at 23:30
  • @sympatric greg: I can repeat that I don't know the commercial version of jqGrid, but I can't imagine that it don't support the 'local' datatype. PHP version for example has the [$dataType](http://www.trirand.com/blog/phpjqgrid/docs/jqGrid/jqGrid.html#var$dataType) parameter. So you should just examine the properties of `Html.Trirand().JQGrid` or probably `Model.ExceptionGrid`. Some property should has the name close to the `DataType`. – Oleg Jun 17 '11 at 06:22