Clinet-side Error handling on Grid Load

Hi There, I'm using WebApiAdaptor to load Grid Data. I want to show a custom error in case of any error on the load event. I tried the action failure Grid event but control never goes there on loading data, then I tried Query, and if Query fails, displays the error. but I'm getting the Type Error please suggest any workaround to get rid of this. or if there is any way to display a custom error in case of an exception on data loading.

Thanks,



1 Reply

PS Pon Selva Jeganathan Syncfusion Team July 26, 2022 03:53 PM UTC

Hi Mohammad Usman,


Thanks for contacting the syncfusion forum. 

Query: I'm using WebApiAdaptor to load Grid Data. I want to show a custom error in case of any error on the load event. please suggest any workaround to get rid of this. or if there is any way to display a custom error in case of an exception on data loading.


Based on your query, we suspect that you want to show the server-side error message while loading the data. We suggest you throw the error message from the server side (controller) and show the error message in the ActionFailure client-side event which is used to catch/receive the error thrown on the server side.


Please refer to the below code snippet,


var dataManager = ej.DataManager({

            url: "/api/Orders",

            adaptor: new ej.WebApiAdaptor(),

            offline: false

        });

       

            $("#Grid1").ejGrid({

 

 

                dataSource: dataManager,

               

                actionFailure: "FailMessage",

                ……

        });

    });

 

 

function FailMessage(args) {

        

        alert(args.error.responseJSON["ExceptionMessage"]);//display the error message

 

    }

 

 

 

 

..

 

Controller:

 

  public PageResult<Orders> Get(ODataQueryOptions opts)

        {

 

            throw new Exception("Test");

 

            return new PageResult<Orders>(emp, null, count);

 

        }

        public void BindDataSource()


In the above code example after the exception thrown from the server side the error has been retrieved using actionFailure event in grid. 


Please refer to the below screenshot,



Please refer to the below help documentation,

https://help.syncfusion.com/aspnet-core/grid/data-binding#handling-http-errors


Please get back to us if you need more assistance. 


Regards, 

Pon selva


Loader.
Up arrow icon