1

In a given webpage I've got, there are two grids: One fetches data from the server and the other waits to be populated based on the row click of the first grid. The idea is: the user selects the records from one grid and the selected row is added to the other table.

My goal is to show a message if the grid has no records. The problem is that "gridComplete" and "loadComplete" events are fired only if the grid actually HAS data to show.

Is there a workaround for this? How can I handle this situation?

Best regards.

darksoulsong
  • 13,988
  • 14
  • 47
  • 90

1 Answers1

0

Both loadComplete and gridComplete will be called event if the server returns empty results. If it's not happens in your grid then the results returned from the server are probably wrong. I recommend you to include loadError callback to the grid to verify this. See the answer for more details about loadError. After you will fix the problem I would recommend you to use loadComplete to show the message which you need. Look at the demo created for the answer. It demonstrate an option how such message can be displayed.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks for the Help. Maybe I wasn't clear enough: the empty grid is not receiving any server response: it is empty on purpose. I'm passing `data: []` to it, so it can render without any records. In this case, those events are never fired. I need some way to figure when the table is empty with JSON data passed to the jqGrid's data option. – darksoulsong Oct 27 '14 at 17:08
  • @darksoulsong: You are welcome! Even if you use `datatype: "local", data: []` (exactly like [the old demo](http://www.ok-soft-gmbh.com/jqGrid/EmptyMsgInBody.htm) which I referenced in my answer) the both callbacks `loadComplete` and `gridComplete` will be called. It's better you provide a demo (in jsfiddle for example) which demonstrates your problem. – Oleg Oct 27 '14 at 17:31
  • I have the same problem, i have datatype: 'json', and server returns {} , but jqGrid doesnt trigger none of the following: loadError, gridGomplete nor loadComplete. Im using free jqGrid 4.13.4 (i want to fix issue with horizontal scroll - when i use inline filter and there is no result, scroll goes automaticly to the left) – bakus33 Nov 14 '16 at 13:06
  • 1
    @bakus33: I can't reproduce your problem. The callbacks `beforeProcessing`, `loadComplete`, `gridComplete` and all other be called in my tests with free jqGrid 4.13.4 and free jqGrid 4.13.5. Probably you should open new question and share the demo which reproduces the problem. I'd recommend you to use 4.13.5 in general, but it's independent from the problem, which you have. – Oleg Nov 14 '16 at 13:36
  • I found the error, thank you Oleg. About issue with scroll: solved it with table.ui-jqgrid-btable { height: 1px; }, which fixed no-scroll issue in previous versions of jqgrid. – bakus33 Nov 15 '16 at 07:58
  • @bakus33: You are welcome! I can only repeat: provide the demo, which I can use to reproduce the problem, if you find someone. The usage of `table.ui-jqgrid-btable { height: 1px; }` isn't good, because it will be applied on non-empty grid. Free jqGrid has [the lines](https://github.com/free-jqgrid/jqGrid/blob/v4.13.5/js/grid.base.js#L4345-L4349), which set the height of empty grid to 1px or clear the CSS style. If it not works in your case **you should provide the corresponding demo**. – Oleg Nov 15 '16 at 08:06
  • @bakus33: **What problem exist in the demo? Could you describe the problem, which demonstrates the demo, and the test case (step by step instruction to reproduce the problem)**. If I comment `data: mydata,` and `height:500` for example then I still be able to scroll the empty grid: https://jsfiddle.net/OlegKi/xxbz5kxq/2/ because free jqGrid set dynamically `height: 1px` on the btable in the special case. – Oleg Nov 15 '16 at 09:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128148/discussion-between-bakus33-and-oleg). – bakus33 Nov 15 '16 at 10:14
  • 1
    @bakus33: I committed [the changes](https://github.com/free-jqgrid/jqGrid/commit/ed9ad664f63d6cf29736e05923b5b433a25c6c94), which should fix the problems which we discussed two weeks ago. You can test the latest code using [RawGit](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs#access-githib-code-from-rawgit) for example. Thank you for the discussion. – Oleg Nov 27 '16 at 22:32