Create custom formatters for a smooth mesh

When writing cell formatters

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

This is the basic definition that we must follow. I can get an explanation in the dataContext argument in the slick grid. What this actually represents.

Exact code for this

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 which dataContext in the code above represents

+3
source share
2 answers

"dataContext" is the data element that the cell for the displayed row is bound to.

+5
source

To make it simpler,

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

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

and now this formatter is called,

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

Now customize it to your requirements.

0

All Articles