簡體   English   中英

如何從ExtJS TableStore中的表格單元格中獲取渲染值

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

我正在構建一個過濾函數,可以過濾我表格中的所有單元格。

為此,我正在遍歷我的tablestore並訪問我的每個記錄項字段,就像這樣。

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

    for (field in rec.data) {

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

我的問題是:如何獲取用戶在HTML頁面中看到的渲染值?

我有許多渲染器,例如日期渲染器,以及從狀態編號創建字符串的渲染器。

上面代碼中的值cellValueAsString只返回基礎值,而不是顯示的值。 有沒有辦法從tableStore和/或rec對象訪問顯示的值?

thhx!

每個Grid列都有一個名為renderer的屬性,它是一個函數。 然后你的任務就是實現這個功能。 為此你可以在某個地方構建一個數組(map fieldName => renderer)並在你的網格和新地方或僅在你的新地方調用它。

請試試這個

將itemclick偵聽器添加到網格中,如下所示

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

將tdCls添加到要從中檢索顯示值的列。如下所示

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

        return value+" hello";

        },
        tdCls:'name-render'

    }

你的函數getRowItems應該如下所示

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


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

}

我認為這是另一種選擇。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM