最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Writing custom formatters for slick grid - Stack Overflow

programmeradmin0浏览0评论

While writing custom cell formatters

 function PercentCompleteFormatter(row, cell, value, columnDef, dataContext)

This is the basic definition we have to follow.can i get explanation about dataContext argument in slick grid.What it actually represents.

The exact code for this is

function PercentCompleteFormatter(row, cell, value, columnDef, dataContext) {
if (value == null || value === "") {
  return "-";
} else if (value < 50) {
  return "<span style='color:red;font-weight:bold;'>" + value + "%</span>";
} else {
  return "<span style='color:green'>" + value + "%</span>";
}
}

I just want what dataContext in above code represents

While writing custom cell formatters

 function PercentCompleteFormatter(row, cell, value, columnDef, dataContext)

This is the basic definition we have to follow.can i get explanation about dataContext argument in slick grid.What it actually represents.

The exact code for this is

function PercentCompleteFormatter(row, cell, value, columnDef, dataContext) {
if (value == null || value === "") {
  return "-";
} else if (value < 50) {
  return "<span style='color:red;font-weight:bold;'>" + value + "%</span>";
} else {
  return "<span style='color:green'>" + value + "%</span>";
}
}

I just want what dataContext in above code represents

Share Improve this question edited May 10, 2012 at 4:45 satheesh asked May 10, 2012 at 4:39 satheeshsatheesh 1,4518 gold badges28 silver badges43 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

"dataContext" is the data item that the cell for the row being rendered is bound to.

To make it more simple,

I wrote this function where i defined my slickgrid and then passed my function to the formatter

    function roundOffValuesFormatter (row, cell, value, columnDef, dataContext) {
        if(dataContext[cellID] || dataContext[cellID]) {
         return Math.round(value*100)/100;  
        } 
    }

and now call this formatter,

{id:'cellID', field:'cellID', name:'Name', width:90, editor:Slick.Editors.Text, formatter: roundOffValuesFormatter}

Now, customize it according to your requirement.

发布评论

评论列表(0)

  1. 暂无评论