4

I have a datagrid with easyui, i create dynamically the headers since they depend on my database. i have gotten my header right already. this is the json object being passed to the datagrid.

[[
  {"field": "status","title": "Estatus","align": "center","rowspan": "2"},
  {"field": "Numero","title": "Orden","align": "center","rowspan": "2"},
  {"field": "FechaRegistro","title": "Fecha","align": "center","rowspan": "2"},
  {"field": "T1","title": "00:02:00","align": "center"},
  {"field": "T2","title": "00:24:00","align": "center"},
  {"field": "T3","title": "00:04:00","align": "center"},
  {"field": "T4","title": "02:00:00","align": "center"},
  {"field": "Cierre","title": "Fecha y Hora<br \/>de Cierre","align": "center","rowspan": "2"}
    ],[
  {"field": "P1","title": "Informacion <br\/>tecnica para <br\/>aprobacion","align": "center","styler": "formatColor"},
  {"field": "P2","title": "Aprobacion de<br\/> Informacion<br\/>Tecnica cliente","align": "center","styler": "formatColor"},
  {"field": "P3","title": "Informacion<br\/>Tecnica de<br\/>Proceso","align": "center","styler": "formatColor"},
  {"field": "P4","title": "Compra y<br\/>Recepcion de<br\/>Materiales","align": "center","styler": "formatColor"}
]]

and i am having a function in my .js

function formatColor(val,row,lol){
var col = "";
for(var name in row){
    col = "";
    var value = row[name];
    if(value === val){
        col = name;

    }
    if(col !=="" && val!==""){
        var opts = $('#dg').datagrid('getColumnOption',col);
        var pr =opts["field"].substring(1);
        var opts2 = $('#dg').datagrid('getColumnOption', 'T'+pr);
        var time = opts2["title"];
        if(val >= time){
            return 'background-color:#ff0000;color:white;';
        }
        else{
            return 'background-color:#00ff00;color:white;';
        }

    }
}

return val;

}

but i get this in my console as error.

Uncaught TypeError: col.styler is not a function

my grid is being populated with a query every second with some times in the P1,P2,P3,P4 columns, the T1,T2,T3,T4 are just the established time that that column should take. So I am trying to make that if my column value is higher than it it will become red background. I have managed to make this work on a fiddle, the problem is that here the headers are not loaded dynamically, and thats whats making it not work( from what i have seen) here is the fiddle link

And this is the way i am setting the headers.

function RefreshHeaders(){
    $.ajax({            
        url:"includes/getHeader.php",
        cache: false,
        timeout: 5000,   
        async: true,    
        success: function(data){
         //console.log(data);
         var objekJSON=jQuery.parseJSON(data);       
         $('#dg').datagrid({
         fit:true,
         fitColumns:false,
         columns:objekJSON,
         url:"includes/Get_Orders.php"
         });
         }
     });


    }

Thanks,

pato.llaguno
  • 741
  • 4
  • 20
  • can you provide more code especially about getHeader.php, how you pass your data into JSON format? and where position you call your function RefreshHeaders? – Hilarius L. Doren Jun 09 '16 at 03:36

0 Answers0