EasyUI Forum
April 24, 2024, 04:39:38 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: how to get the field name inside an styler function?  (Read 4848 times)
r2ferna
Newbie
*
Posts: 21


View Profile
« on: June 16, 2015, 06:49:42 PM »

Hi:

I am adding some fields (31) to a datagrid. They are added dynamically depending on user inputs.
I want to use just one styler function for all the 31 fields, but I need the field-name to make decisions inside the styler code.

The styler function recives only three parameters:
 value: the field value.
 rowData: the row record data.
 rowIndex: the row index.

How can I send the field-name?
I have tried the next with no luck:

Code:
    function modificaGrid(){
    var numDias = $('#inpDiffDays').val();
        var jsDate = js2_parserDate( $('#inpFechaD').datebox('getValue') );
        var newCols = [];
        for (i=1;i<=numDias;i++) {   /* numDias = 31 */
            var campo = 't-eh-&1'.replace('&1',i);
            var diaAlfa = js2_weekDay(jsDate);
            var title = '&1 &2-&3'
                .replace('&1',diaAlfa.substr(0,2))
                .replace('&2',('0'+(jsDate.getMonth()+1)).slice(-2))
                .replace('&3',('0'+jsDate.getDate()).slice(-2));
            var col = {
                    field:campo, title:title, width:60, align:'center',
                    styler:function(value,row,index){ console.log('inside styler: ', campo);
                               local_tehStyler(value,row,index,campo);
                     },
                     /* here: campo inside styler  = the last value (t-eh-31), but every field value is OK!! */
                };
            newCols.push(col);
            jsDate = js2_addDaysToDate(jsDate,1);
        }
        var cols = g_dfltCols.concat(newCols); newCols=[];
        console.log(cols);
        $('#dg').datagrid({columns:[cols]}); cols=[];
    }

with this code:
Code:
   styler:function local_tehStyler(value,row,index,campo){console.log('inside styler: ', campo);},
the campo is undefined!

The styler function is something like:
Code:
function local_tehStyler(value,row,index,campo){
        var numColor = null;
        console.log(campo);
        var numField = last-part-of-the-field-name(campo);
        var anotherField = 't-por-&1'.replace('&1',numField);
        var tpor = row[anotherField];
        if (tpor=='R') numColor=14; else if(tpor=='W') numColor=6; else if (tpor=='M') numColor=12
        else if(tpor=='O') numColor=13;
        return 'background:&1;'.replace('&1',js1_traduceNumColor(numColor));
      }

MTIA.
Logged
r2ferna
Newbie
*
Posts: 21


View Profile
« Reply #1 on: June 18, 2015, 05:35:03 PM »

Forget it guys, I was lost. It is so easy:
Code:
this.field
is the solution!!
 Embarrassed
Bye.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!