如何将自定义Fliter格式化应用于Slick网格自定义单元格格式化程序 [英] How to apply custom Fliter formatter in a Slick grid custom cell formatter

查看:146
本文介绍了如何将自定义Fliter格式化应用于Slick网格自定义单元格格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在光滑网格自定义单元格格式化程序中应用自定义角度过滤器格式化程序

How to apply custom angular filter formatter in slick-grid custom cell formatter

假设我有一个角度客户过滤器格式化程序,将日期从一种格式转换为另一种格式。

Suppose I have an angular customer filter formatter that convert the date from one format to another format.

var dateFilter = this.$filter('myDateFilterFormatter')('2006-04-07'); 

它返回为4/7/06。

It returns as 4/7/06.

如何在slick-grid自定义单元格格式化程序中使用myDateFilterFormatter

How can I use myDateFilterFormatter in slick-grid custom cell formatter

我已经尝试过这样的方式

I have tried this way

this.dateFommatter = function(row, cell, value, columnDef, dataContext){
            return "<p>"+ value | myDateFilterFormatter +"</p>";
        };

并尝试

this.dateFommatter = function(row, cell, value, columnDef, dataContext){
                return "<p>"+ this.$filter('myDateFilterFormatter')(value) +"</p>";
            };

两种方式都以错误结尾。我无法在光栅网格格式化程序中应用自定义过滤器。你可以建议,如何在光滑网格中使用自定义过滤器。

Both the way ends with error. I am unable to apply custom filter in slick-grid row formatter. Can you please suggest, How can I use custom filter in slick-grid.

推荐答案

code>里面的 dateFormatter 函数是指函数本身。

this inside the dateFormatter function refers to the function itself.

通常使用类似

var self = this;

... code ...

this.dateFommatter = function(row, cell, value, columnDef, dataContext){
    return "<p>"+ self.$filter('myDateFilterFormatter')(value) +"</p>";
};

要回答第二个查询,调用格式化程序的代码是,例如

To answer your second query, the code that calls the formatter is, for example

function updateCell(row, cell) {
  var cellNode = getCellNode(row, cell);
  if (!cellNode) {
    return;
  }

  var m = columns[cell], d = getDataItem(row);
  if (currentEditor && activeRow === row && activeCell === cell) {
    currentEditor.loadValue(d);
  } else {
    cellNode.innerHTML = d ? getFormatter(row, m)(row, cell, getDataItemValueForColumn(d, m), m, d) : "";
    invalidatePostProcessingResults(row);
  }
}

我想你是要求访问 cellNode
您可以添加

I think you are asking about getting access to cellNode. You can add

var cellNode = grid.getCellNode(row, cell);

如果你喜欢,你的格式化程序。

to your formatter if you like.

从长远来看,如果您发现有权访问单元节点,可以修改格式化程序函数,并对其进行所有调用,以添加 cellNode 到参数列表的末尾。这将是对slickgrid代码的修改。

In the long run, if you find it useful to have access to the cell node, you could modify the formatter function, and all calls to it, to add the cellNode to the end of the parameter list. This would be a modification to the slickgrid code, however.

编辑:实际上我只是测试了这个,它不起作用,因为在单元格创建时,格式化程序在创建单元格。我在最新版本的SlickGrid中修改了格式化程序,因此,您可以选择返回一个对象 {text:'displayText',removeClasses:'class1 class2',addClasses:'class1'},而不是返回一个字符串,并且在应用格式化程序时,类将被删除并添加到单元格中。删除一系列类允许先前的格式化类被清除,然后再应用正确的新类。

actually I just tested this and it doesn't work because on cell creation the formatter is called before the cell is created. I have modified the formatter in the latest release of SlickGrid so that instead of returning a string you can optionally return an object { text: 'displayText', removeClasses: 'class1 class2', addClasses: 'class1' } and the classes will be removed and added to the cell when the formatter is applied. Removing a range of classes allows previous formatting classes to be cleared before applying the correct new class.

这篇关于如何将自定义Fliter格式化应用于Slick网格自定义单元格格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆