0

I want to catch errors while creating jqGrid definition like mismatch of col_names and col_model or errors while cell custom formatting. The purpose is to catch these errors and display as an overlay over grid placeholder.
If I place try catch outside grid definition , control never comes in catch block but error is by default shown as alert dialog.

Any suggestions please.

Seedika
  • 73
  • 7

1 Answers1

0

I think that the example with mismatching of the size of colNames and colModel is not good example. Is you use cn and cm for example as the values of colNames and colModel parameters you can just include if (cn.length !== cm.length) {...} in your code before you create jqGrid. The current code of jqGrid do the same (see here).

In general there are no common way how jqGrid or other plugins reports errors. jQuery for example introduces jQuery.error function which you can overwrite in general. The problem is that the function will be used in very small subset of jQuery code. So it can't really help in my opinion. The most jQuery functions has no validation of input parameters. So you can have unpredictable results if you use wrong parameters.

Moreover many parts of jqGrid code works asynchronously. So one should make validation mostly in other way. I recommend you for example to use loadError callback. See the answer and another one for more details.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Ok. Thanks Oleg! I understand that I have to handle different grid events for different errors. The links covers most of them. Thanks for help. – Seedika Nov 22 '12 at 08:38
  • 1
    @Seedika: You are welcome! If you use other features of jqGrid there are corresponding additional features which allows you to customize reporting of error. For example form editing has [errorTextFormat](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing#events) callback and so on. – Oleg Nov 22 '12 at 08:59