Advertisement
gridphp

Untitled

Mar 24th, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Q) How to apply more advanced conditional formatting?
  2.  
  3. You can set onload event in PHP code, and enable 'reloadedit' option
  4.  
  5.     // set js onload event
  6.     $e["js_on_load_complete"] = "grid_onload";
  7.     $g->set_events($e);
  8.      
  9.     // required to format rows after editing
  10.     $opt["reloadedit"] = true;
  11.     ...
  12.     $g->set_options($opt);
  13.      
  14. Then in HTML code, you can have custom conditional logic in javascript handler.
  15. In this code, list1 is grid id. You can also use php's equivalent '$g->id' to reference it.
  16.      
  17.     <script>
  18.     function grid_onload(ids)
  19.     {
  20.         if(ids.rows)
  21.             jQuery.each(ids.rows,function(i)
  22.             {
  23.                 // if col1 = yes and col2 = n/a, format row
  24.                 if (this.col1.toLowerCase() == 'yes' && this.col2.toLowerCase() == 'n/a')
  25.                 {
  26.                     // highlight row
  27.                     jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit').css({'background-color':'#FBEC88', 'color':'red'});
  28.                 }
  29.  
  30.                 // if col3 = 1, format cell. 'aria-describedby=list1_col3' is 'gridid_colname' convention to identify cell.
  31.                 if (parseInt(this.col3) == 1)
  32.                 {
  33.                     // highlight cell
  34.                     jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
  35.                     jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_col3]').css('background','inherit').css({'background-color':'#FBEC88', 'color':'red'});
  36.                 }
  37.             });
  38.     }
  39.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement