简体   繁体   中英

how to change the value of column of grid dynamically in extjs

Blockquote

header:WtfGlobal.getLocaleText("hrms.performance.self.rating"),
              dataIndex:'gemprat',
              sortable:true,
              renderer: function(value, meta, record) {
                  debugger;
                  var val = record.get('gemprat');
                  console.log(val); 
                  if (val === '5') {
                      record.set('gemprat', 'CEE');
                  } 
              }

Blockquote please help me to alter this value

A column renderer is an 'interceptor' method which can be used to transform data (value, appearance, etc.) before it is rendered. The return value is the HTML string to be rendered.

First of all, create an object from data array for easy access.

var data = [['5','CEE' ],['4','GEE'],['3','ME'],['2','UME'],['1','NME']];
var newDataObj = {};
data.forEach(function(a){ newDataObj[a[0]]=a[1]; });

Creates an Object with values as {1: "NME", 2: "UME", 3: "ME", 4: "GEE", 5: "CEE"}

If data array is static, you can directly create an object with above data.

Now change your renderer function as shown below.

 renderer: function(value, meta, record) {        
     // var val = record.get('gemprat'); No need for this line since dataIndex for this column is gemprat.
      return newDataObj[value];
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM