【问题标题】:Writing custom formatters for slick grid为光滑网格编写自定义格式化程序
【发布时间】:2012-05-10 04:39:45
【问题描述】:

在编写自定义单元格格式化程序时

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

这是我们必须遵循的基本定义。我能得到关于光滑网格中 dataContext 参数的解释吗。它实际代表什么。

具体代码是

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>";
}
}

我只想要上面代码中的dataContext代表什么

【问题讨论】:

    标签: javascript slickgrid


    【解决方案1】:

    “dataContext”是正在渲染的行的单元格绑定到的数据项。

    【讨论】:

    • 在此示例中,PercentCompleteRenderer 显示任务的完成百分比字段。 “dataContext”就是那个任务。
    • 任务你的意思是网格中的完整行
    • 是的。 SlickGrid wiki 上的基本示例在网格中显示任务,这就是我使用的。
    【解决方案2】:

    为了更简单,

    我在定义我的 slickgrid 的地方编写了这个函数,然后将我的函数传递给 formatter

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

    现在调用这个格式化程序,

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

    现在,根据您的要求对其进行自定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      相关资源
      最近更新 更多