3

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

satheesh
  • 1,443
  • 7
  • 28
  • 41

2 Answers2

5

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

Tin
  • 9,082
  • 2
  • 34
  • 32
0

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.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Aamir Shaikh
  • 83
  • 1
  • 4