jqGrid error message from server side exception

2019-06-04 07:03发布

问题:

I've added the following code for my jqgrid:

changeTextFormat = function (data) {

                return "Activity or one from the same price group already used";
            };
            jQuery.extend(jQuery.jgrid.edit, {errorTextFormat: changeTextFormat })

It works great for insert and I get the error message appearing in the top of the dialog.

However for edits it's not working so well. Instead a massive dialog is appearing with the error message.

I'm currently thinking that it's because I'm using inline editing so it has to pop up a whole new dialog. Is there a way to format this dialog better. I'm pretty sure that for the inline edits it's not even running through changeTextFormat after an exception.

回答1:

It's correct. By changing of jQuery.jgrid.edit you set errorTextFormat only for the form editing. In case of the usage inline editing you have to use errorfunc parameter of the editRow.

You can easy see the difference between errorTextFormat and errorfunc parameter. If in the errorTextFormat you should return the error message which will be used in the error message, the callback function errorfunc should display the corresponding error message itself. If you want to have the same look of the error dialog you can use $.jgrid.info_dialog method. In the answer you could find the corresponding code fragment. See additionally the code fragment of the jqGrid source code.