About JqGrid Process Processes

I just want to better understand the JqGrid event process.

  • beforeRequest
  • loadBeforeSend
  • serializeGridData li>
  • loadError
  • gridComplete
  • loadComplete

Based on these events

  • If I want to add a filter or additional parameters to an ajax request to the server, should I do this in loadBeforeSend correctly?
  • After I get the data from the server, if I want the data not to be displayed in the grid (I want to process it first and display only the processed data), should I do this in gridComplete correctly?

Since my work requires me to add additional parameters when sending a request to the server, and after receiving the data, I need to stop the grid from displaying data in the grid so that I can process the data further before displaying the processed data in the grid. But I could not understand what JqGrid event I should put to my function.

thanks

===================================================

EDIT:

For the postData part p>

loadBeforeSend: function () { if (sessionStorage.pathStates == "edit" && location.pathname.indexOf("list") > -1){ console.log("SUCCESS"); loadFilter(); } }, 

And loadFilter

 function loadFilter(){ var filter = JSON.parse(sessionStorage.filter); var filterInput = [], model = [], filters = {}; filterInput = filter.filterInput; model = filter.model; var grid = filter.grid, page = filter.page, op = "bw", a = 0, b = 0; filters = {groupOp: "AND", rules: []}; for (var i = 0; i < model.length; i++){ if (filterInput[a].length > 0){ filters.rules.push({field:model[a], op:"bw", data:filterInput[a]}); } a++; } $(grid).jqGrid('setGridParam', { search: true, postData: {filters: JSON.stringify(filters)} }).trigger('reloadGrid'); } 

As for beforeProcessing, I still don't know about this. But the process that I had in mind is something like this

 beforeProcessing: function (data) { if (sessionStorage.pathStates == "edit" && location.pathname.indexOf("list") > -1){ >>Filter data based on certain criterias, like for example, changing one of the column format, or only displaying data that has the value of xxx on certain column >>Return the filtered data } }, 
+6
source share
1 answer

I find your question interesting. I agree that the current jqGrid documentation describes event handling and callbacks not clearly enough. Therefore, I will describe in the first place the processing in detail. I will only consider the remote datatype case you need ( datatype: "json" or datatype: xml ). Later I will come back to you in a specific case and write my recommendations for you.

Before calling beforeRequest callback jqGrid build data parameters used in the corresponding Ajax request that will be sent to the server.

  • Option
  • prmNames allows you to configure the names of the standard parameters that will be sent to Ajax to the server. The same prmNames parameter allows prmNames to remove some parameters by setting the corresponding value to null .
  • postData option allows you to expand the parameters that will be sent to the server. The postData value will be used in $.extend (see here ) to combine additional parameters with standard parameters. jqGrid uses the resulting postData parameter as the value of the jQuery.ajax data parameter . jQuery allows you to use data either as a string or as an object with properties of functions. Using a function is very useful in some scenarios: see the answer for more details.
  • The jQuery event "jqGridBeforeRequest" will fire. You can return the string "stop" from a false boolean to stop subsequent processing of requests to the server. You can change the postData parameter inside the jqGridBeforeRequest event descriptor.
  • callback beforeRequest works just like the jQuery event "jqGridBeforeRequest", but you can define only one callback for each grid. The callback may return false to stop the request. To access the grid options, you can use this (see answer ).
  • The optional serializeGridData callback is a past ability to control the information that will be sent to the server. If the serializeGridData callback is defined, it must return either a string to be sent to the server, or an object with properties or functions. The returned object will be used as the value of the data parameter jQuery.ajax .
  • when processing an Ajax request, jQuery may call additional functions defined in postData . In addition, jQuery will call loadBeforeSend . For example, you can use the loadBeforeSend to modify / extend the HTTP headers of an Ajax request. See the answer for a sample code. You can return false from loadBeforeSend to force an Ajax request to stop.

Now jQuery,ajax wait a bit for a response from the server. If necessary, you can change the default timeout values. See the answer .

If the recipient receives a response from the server and the response contains a successful HTTP status code (value less than 400), then jqGrid interprets the response as successful and processes it in one way. Corrected answers will be processed differently.

There is an important beforeProcessing that allows you to pre-process the server response before it is processed by jqGrid. You can modify or expand the data returned from the server. See answer for example. In addition, jqGrid allows you to break the standard processing of server responses to beforeProcessing callbacks. If the callback returns false , then jqGrid interrupts the processing and simply ignores the server response.

Then jqGrid processes the server response. It will be interpreted as a JSON or XML response XML on the datatype option for jqGrid. During data processing, some other callback functions defined inside jsonReader or xmlReader (see here ) or defined in jsonmap / xmlmap (see examples here and here ).

After processing the visible jqGridGridComplete data page, an jqGridGridComplete will be jqGridGridComplete will be called, after which jqGridAfterGridComplete will be launched.

After the entire server response has been processed (it is especially important if you use the loadonce: true option), then the jqGridLoadComplete event will be fired, the jqGridLoadComplete will be called and the jqGridAfterLoadComplete event will occur.

I recommend that you read the answer , which details the differences between loadComplete and gridComplete .

On the other hand, if the server response failed due to a timeout or because the response contains an invalid HTTP status code, calling calls will not be called. Instead, only the loadError callback is called. The answer will discuss the callback in detail. I strongly recommend defining a loadError in all of your productive code that uses jqGrid. It should display an error message on the server.

Now I will return to your specific case.

I would recommend you use postData add additional parameters when sending a request. All static parameters that you can directly define as properties. All dynamic parameters that you can define as functions.

In addition, I would recommend using the beforeProcessing . This allows, for example, to stop displaying the grid data. You can read and analyze data returned from the server. You can easily change data (for example, delete some fields).

+6
source

Source: https://habr.com/ru/post/971207/


All Articles