Witam.
Używam jqGrid i poniżej mam pewną funkcję, która działa prawidłowo tzn. koloruje mi jedno z wypisanych pól z bazy - koloruje pole gdzie data przekracza 180dni, ale jak pokolorować cały rekord, gdzie data przekracza 180 dni? Jak to zrobić?

  1. jQuery('document').ready(function() {
  2. jQuery("#list").jqGrid({
  3. url:'pos_php.php',
  4. colNames:['ID','Media','Kat.','N. ident.','Autor','Tytuł', 'Wydawnictwo', 'Miasto','Rok','Opis','Data wyp.','Obcojęzyczne'],
  5. colModel :[
  6. {name:'id' ,index:'id' ,width:50 ,align:"right" ,editable:false},
  7. {name:'Med' ,index:'Med' ,width:70 ,align:"left" ,editable:true},
  8. {name:'Kat' ,index:'Kat' ,width:70 ,align:"left" ,editable:true},
  9. {name:'Nr_id' ,index:'Nr_id' ,width:90 ,align:"left" ,editable:true},
  10. {name:'Autor' ,index:'Autor' ,width:150 ,align:"left" ,editable:true},
  11. {name:'Tytul' ,index:'Tytul' ,width:300 ,align:"left" ,editable:true},
  12. {name:'Wydawnictwo' ,index:'Wydawnictwo' ,width:130 ,align:"left" ,editable:true},
  13. {name:'Miasto' ,index:'Miasto' ,width:130 ,align:"left" ,editable:true},
  14. {name:'Rok' ,index:'Rok' ,width:50 ,align:"left" ,editable:true},
  15. {name:'Opis' ,index:'Opis' ,width:150 ,align:"left" ,editable:true},
  16. {name:'Data_wyp' ,index:'Data_wyp' ,width:80 ,align:"right",
  17. formatter: function (cellvalue) {
  18. var color;
  19.  
  20. var txt=String(cellvalue);
  21.  
  22. var rok = txt.substring(0, 4); //pobieramy teraĽniejszy rok
  23. var miesiac1=txt.substring(5, 6);
  24. var miesiac2=txt.substring(6, 7);
  25. if (miesiac1=="0"){
  26. miesiac= miesiac2;
  27. }
  28. else{
  29. miesiac=miesiac1+miesiac2;
  30. }
  31. var dzien = txt.substring(8, 10);
  32.  
  33. var myDate=new Date();
  34. myDate.setFullYear(rok,miesiac-1,dzien);
  35. var today = new Date();
  36.  
  37. var roznica = (today-myDate);
  38.  
  39. var ms_w_dniu = 24 * 60 * 60 * 1000;
  40. var e_zostaloDni = roznica / ms_w_dniu;
  41.  
  42. if (e_zostaloDni>180) {color = 'tomato';}
  43.  
  44.  
  45. return '<span class="cellWithoutBackground" style="background-color:' + color + ';">' + cellvalue + '</span>';
  46. //return '<span class="cellWithoutBackground" style="background-color:' + color + ';">' + cellvalue + '</span>';
  47. return cellvalue;
  48. }
  49.  
  50.  
  51. },
  52. {name:'Obcojezyczne' ,index:'Obcojezyczne' ,width:80 ,align:"left" ,editable:true},
  53. ],
  54. datatype: "json",
  55. height: "100%",
  56. rowNum:10,
  57. rowList : [10,20,30,40],
  58. mtype: "POST",
  59. pager: '#pager',
  60. sortname: 'Tytul',
  61. rownumbers: true,
  62. viewrecords: true,
  63. sortorder: "asc",
  64. caption: "Media",
  65. });
  66. jQuery("#list").jqGrid('filterToolbar');