SMART datagrid v.1 > Examples

Back  Forward

Lookup Data  Example

如果DataColumn.lookupDisplay被指定为true, 就可以通过设置DataColumn.lookupValueslabelFieldlookupSourceId等, 替代连接在单元格的数据字段,而从其他区域获取值,并且将其显示在数据单元格。 

首先,可以参考数据查找概述而获取所需信息。 


1. LookupValues & LookupLabels

如果在lookupValues中设置一个以上的值,并且在lookupLabels中设置超过lookupValues的项目数量, 同时如果lookupValues中存在相关数据单元格的值,就可以将相关位置的lookupLabels项目值用于显示数据单元格。 

下列"产品名"列,虽然连接在与"产品代码"相同的"product_id"字段上,但已在其中设置了lookupValues和lookupLabels。 列的lookupDisplay属性将会根据"Lookup Display"的勾选状态而发生变更。 

 

Grid - 1
rows

2. Label Field

下列网格中,"客户名"列的fieldName属性被设置为"customer_id",并且labelField属性被设置为"customer_label"。 如果列的lookupDisplay属性为false,就会如同"客户识别码"列,将会显示"customer_id"字段值。 但是,如果勾选Lookup Display并将列的lookupDisplay属性设置为true,则会显示通过labelField设置的"customer_label"字段值。 

Code -1
    chkLookupDisplay_click: function (ev) {
        var col = grdMain.columnByName('colCustName');
        if (col) {
            col.setLookupDisplay(ev.target.checked);
        }
    }

 

Grid - 2
rows

3. Lookup Tree

LookupTree是一种以阶层结构储存由多个值所构成的关键字和关键字的值的LookupSource体现方式。 如果将LookupTree对象注册在网格中,并且将其ID指定为列的lookupSourceId, 同时在lookupKeyFields中指定将被用于查找关键字的字段,列的数据单元格将会被用于获取和显示LookupTree对象的值。 

下列网格中,"产品客户"列的lookupSourceId已被指定为注册在网格中的"prodCustomers"查找源, 并且lookupKeyFields已被设置为["product_id", "customer_id"]。 

有关详细说明,请参考LookupSourceLookupTree帮助主题。 

Code -2
    grdMain3.addLookupSource({
        id: "prodCustomers",
        levels: 2,
        keys: [
            ['PR_001', 'AAPL'],
            ['PR_002', 'MSFT'],
            ...
        ],
        values: [
            "PR_001_Apple",
            "PR_002_Microsoft",
            ...
        ]
    });    

 

Grid - 3
rows

查看源代码 JSP 

See Also
数据查找概述
lookupDisplay
Examples
标号字段
衍生字段
计算列