Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Previous revision
wiki:events [2014/11/08 17:31]
wiki:events [2018/02/02 20:54] (current)
admin
Line 1: Line 1:
-~~ODT~~ 
 ====== Events ====== ====== Events ======
  
Line 5: Line 4:
 The action to take on an event is set as a property of the grid, e.g. The action to take on an event is set as a property of the grid, e.g.
  
-See also [[wiki:​methods|jqGrid Methods]].+See also [[wiki:​methods|jqGrid Methods]]
  
 <code javascript>​ <code javascript>​
Line 135: Line 134:
  
 ===== Return values from triggered events ===== ===== Return values from triggered events =====
-Some from events in the above list should or have to return events. One should take in the consideration that one can register multiple event handles. The event handle should use [[result]] property of the event object to know the value returned from the previously invoked event handler. Depend on the type of returned value one should combine the results which one plan to return with the results returned by previous handler.+Some from events in the above list should or have to return events. One should take in the consideration that one can register multiple event handles. The event handle should use **[[http://​api.jquery.com/​event.result/​|result]]** property of the event object to know the value returned from the previously invoked event handler. Depend on the type of returned value one should combine the results which one plan to return with the results returned by previous handler.
  
-For example one implements jqGridBeforeSelectRow event handler which can return boolean true/false or "​stop"​ string. The event will be called on click inside of the grid. jqGrid trigger jqGridBeforeSelectRow event before making selection of the clicked row. If the returned value is false or "​stop",​ jqGrid will don't make selection. So if should be clear that jqGridBeforeSelectRow event handler can return false if one decide to suppress row selection, but if the selection should be permitted ​one should return true only if **result** property of the first **e** parameter ​is undefined ​and one should ​return **e.result** ​if it is not undefined:+For example one implements ​**jqGridBeforeSelectRow** event handler which can return boolean ​**true**/**false** or **"​stop"​** string. The event will be called on click inside of the grid. jqGrid trigger ​**jqGridBeforeSelectRow** event before making selection of the clicked row. If the returned value is **false** or **"​stop"​**, jqGrid will don't make selection. So it should be clear that **jqGridBeforeSelectRow** event handler can return ​**false** if one decide to suppress row selection, but one couldn'​t just return **true** ​if the selection should be permitted. It will force selection even if //​previously//​ invoked event handler returns ​**false**. So one have to test **[[http://​api.jquery.com/​event.result/​|result]]** property of **e** parameter. If it's **undefined** then there are no other event handler which was invoked previously. On the other side if the value **e.result** is **false** or **"​stop"​** then the //​previously//​ invoked event handler decide to suppress selection. In the case one have to return ​the value **e.result** ​(**false**) instead of **true**. It means that we don't want to //force// the selection. We just //​don'​t protest the selection// and we want to follow the decision of //​previously//​ invoked event handler about the selection. The corresponding code could be the following:
  
 <code javascript>​ <code javascript>​
 $("​gridid"​).bind("​jqGridBeforeSelectRow",​ function (e, rowid, orgClickEvent) { $("​gridid"​).bind("​jqGridBeforeSelectRow",​ function (e, rowid, orgClickEvent) {
     ...     ...
-    // we want return true, but we should test e.result additionally+    // if we want to return true, we should test e.result additionally
     return e.result === undefined ? true : e.result;     return e.result === undefined ? true : e.result;
 }); });
 </​code>​ </​code>​
  
-alternatively ​one can test explicitly for for false or "​stop":​+Alternatively ​one can test explicitly for for false or "​stop":​
  
 <code javascript>​ <code javascript>​
 $("​gridid"​).bind("​jqGridBeforeSelectRow",​ function (e, rowid, orgClickEvent) { $("​gridid"​).bind("​jqGridBeforeSelectRow",​ function (e, rowid, orgClickEvent) {
     ...     ...
 +    // if we want to return true, we should test e.result additionally
     return e.result === false || e.result === "​stop"​ ? false : true;     return e.result === false || e.result === "​stop"​ ? false : true;
 }); });

QR Code
QR Code wiki:events (generated for current page)