简体   繁体   English

如何从ExtJS TableStore中的表格单元格中获取渲染值

[英]How do I get the rendered value from a table cell in ExtJS TableStore

I am building a filter function that filters across all cells in my table. 我正在构建一个过滤函数,可以过滤我表格中的所有单元格。

To do this I am iterating through my tablestore and accessing each of my record item fields, like so. 为此,我正在遍历我的tablestore并访问我的每个记录项字段,就像这样。

tablestore.each(function (rec, idx) {
    contains = false;

    for (field in rec.data) {

        var cellValueAsString = "" + rec.data[field]
    }
}

My question is: how do I get the rendered value that the user sees in the HTML page? 我的问题是:如何获取用户在HTML页面中看到的渲染值?

I have a number of renderers, eg a date renderer, and a renderer which creates strings from a status number. 我有许多渲染器,例如日期渲染器,以及从状态编号创建字符串的渲染器。

the value cellValueAsString in the above code just returns the underlying value, and not the displayed value. 上面代码中的值cellValueAsString只返回基础值,而不是显示的值。 Is there any way of accessing the displayed value from the tableStore and/or the rec object? 有没有办法从tableStore和/或rec对象访问显示的值?

thhx! thhx!

Every Grid column has a property called renderer , which is a function. 每个Grid列都有一个名为renderer的属性,它是一个函数。 Your task is then to get to this function. 然后你的任务就是实现这个功能。 And for that you could build somewhere an array (map fieldName => renderer) and call it both in your grid and in the new place or only in your new place. 为此你可以在某个地方构建一个数组(map fieldName => renderer)并在你的网格和新地方或仅在你的新地方调用它。

Please try this 请试试这个

Add the itemclick listener to your grid as follows 将itemclick侦听器添加到网格中,如下所示

listeners:{
            itemclick: this.getRowItem,
            scope:this
        }

Add a tdCls to your column from which you want to retrieve the display value.Like below 将tdCls添加到要从中检索显示值的列。如下所示

{ 
   text: 'Name',  
   dataIndex: 'name',
   renderer: function(value, metadata, record){

        return value+" hello";

        },
        tdCls:'name-render'

    }

Your function getRowItems should be like the below 你的函数getRowItems应该如下所示

getRowItem: function(gridPanel, record, item, index, e, eOpts){


   var tdItem= item.getElementsByClassName('name-render');
   var actualTextDisplayed = tdItem.firstChild.innerHTML;
   return actualTextDisplayed ;

}

This is alternative i think. 我认为这是另一种选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM