简体   繁体   English

ExtJS6:在gridpanel的列中传递整个对象或2个字段

[英]ExtJS6: Passing entire object or 2 fields in gridpanel's columns

While building GridPanel's column values I need to lookup for a field if that field does not have a value, it should look for another field and render it as a column value. 在构建GridPanel的列值时,如果该字段没有值,我需要查找字段,它应该查找另一个字段并将其呈现为列值。 Now as per ExtJS6 docs , we could pass a single data attribute to dataIndex and mould value via rendered function. 现在根据ExtJS6文档 ,我们可以通过渲染函数dataIndex单个数据属性传递给dataIndex并模拟值。 But there is no mention how one can use fallback attribute if mentioned field does not have a value. 但是如果提到的字段没有值,则没有提及如何使用fallback属性。

Here is snippet: 这是片段:

{
  text: 'Title',
  flex: 1,
  dataIndex: '<how-to-pass-object-itself-or-two-fields>',
  renderer: function(value, metaData) {
    return '<i class="fa fa-bars"></i>' +  value;
  }
}

The renderer function has more in-parameters. 渲染器函数具有更多参数。

You can grab all fields off of the record. 您可以从记录中获取所有字段。

var DEFAULT_VALUE = '';

{
    dataIndex : 'a' // or could be 'b', or 'c' or etc…
    renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
        var fieldA = record.get('a');
        var fieldB = record.get('b');
        var fieldC = record.get('c');

        // …

        return value || DEFAULT_VALUE; // ?
    }
}

In the return statement, just replace DEFAULT_VALUE with one of your other field values or an actual default value. 在return语句中,只需将DEFAULT_VALUE替换为您的其他字段值或实际默认值。

If your grid is sortable on the client side, you should be careful when using renderer for rendering different record values in your column. 如果您的网格在客户端可以排序,则在使用renderer在列中呈现不同的记录值时应该小心。

You can also look at convert method in Ext.data.field.Field 您还可以在Ext.data.field.Field查看convert方法

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

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