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ć? jQuery('document').ready(function() {
jQuery("#list").jqGrid({
url:'pos_php.php',
colNames:['ID','Media','Kat.','N. ident.','Autor','Tytuł', 'Wydawnictwo', 'Miasto','Rok','Opis','Data wyp.','Obcojęzyczne'],
colModel :[
{name:'id' ,index:'id' ,width:50 ,align:"right" ,editable:false},
{name:'Med' ,index:'Med' ,width:70 ,align:"left" ,editable:true},
{name:'Kat' ,index:'Kat' ,width:70 ,align:"left" ,editable:true},
{name:'Nr_id' ,index:'Nr_id' ,width:90 ,align:"left" ,editable:true},
{name:'Autor' ,index:'Autor' ,width:150 ,align:"left" ,editable:true},
{name:'Tytul' ,index:'Tytul' ,width:300 ,align:"left" ,editable:true},
{name:'Wydawnictwo' ,index:'Wydawnictwo' ,width:130 ,align:"left" ,editable:true},
{name:'Miasto' ,index:'Miasto' ,width:130 ,align:"left" ,editable:true},
{name:'Rok' ,index:'Rok' ,width:50 ,align:"left" ,editable:true},
{name:'Opis' ,index:'Opis' ,width:150 ,align:"left" ,editable:true},
{name:'Data_wyp' ,index:'Data_wyp' ,width:80 ,align:"right",
formatter: function (cellvalue) {
var color;
var txt=String(cellvalue);
var rok = txt.substring(0, 4); //pobieramy teraĽniejszy rok
var miesiac1=txt.substring(5, 6);
var miesiac2=txt.substring(6, 7);
if (miesiac1=="0"){
miesiac= miesiac2;
}
else{
miesiac=miesiac1+miesiac2;
}
var dzien = txt.substring(8, 10);
var myDate=new Date();
myDate.setFullYear(rok,miesiac-1,dzien);
var today = new Date();
var roznica = (today-myDate);
var ms_w_dniu = 24 * 60 * 60 * 1000;
var e_zostaloDni = roznica / ms_w_dniu;
if (e_zostaloDni>180) {color = 'tomato';}
return '
<span class="cellWithoutBackground" style="background-color:' + color + ';">' + cellvalue + '
</span>';
//return '
<span class="cellWithoutBackground" style="background-color:' + color + ';">' + cellvalue + '
</span>';
return cellvalue;
}
},
{name:'Obcojezyczne' ,index:'Obcojezyczne' ,width:80 ,align:"left" ,editable:true},
],
datatype: "json",
height: "100%",
rowNum:10,
rowList : [10,20,30,40],
mtype: "POST",
pager: '#pager',
sortname: 'Tytul',
rownumbers: true,
viewrecords: true,
sortorder: "asc",
caption: "Media",
});
jQuery("#list").jqGrid('filterToolbar');