SMART datagrid v.1 > Examples

Back  Forward

Label Field  Example

labelField数据查找的最简单的体现方式。 我们将会替代原本连接在列单元格上的数据字段的值,而显示通过labelField属性而指定的字段值。 

下列网格中,"本国货币"列将"country_currency"字段指定为labelField。 

Grid - 1
rows

这时,如果是初次加载数据组后进行编辑的情况,就需要进行适当的同步。 在数据组级别上,将会通过在GridDataSet.onRowUpdatedonRowInserted事件中,变更标签字段的值, 而在处于编辑状态的网格行中所进行的同步,将会在GridBase.onEditCellUpdated事件内,通过变更相关标签字段的值而进行处理。 

Code -1
    dsMain.onRowUpdated = function (ds, row) {
        ds.setValue(row, 'country_currency', ds.getValue(row, 'country') + '_' + ds.getValue(row, 'currency'));
    };
Code -2
    dsMain.onRowInserted = function (ds, row) {
        ds.setValue(row, 'country_currency', ds.getValue(row, 'country') + '_' + ds.getValue(row, 'currency'));
    };
Code -3
    grdMain.onEditCellUpdated = function (grid, row, fieldIndex, newValue, oldValue) {
        var f1 = dsMain.getFieldIndex('country');
        var f2 = dsMain.getFieldIndex('currency');
        if (fieldIndex == f1 || fieldIndex == f2) {
            row.setValue(dsMain.getFieldIndex('country_currency'), row.getValue(f1) + '_' + row.getValue(f2));
        }
    }

为了使labelField能够正常动作,需要将DataColumn.lookupDisplay指定为true。 而且,如果使用衍生字段,就可以更容易体现。 

查看源代码 JSP 

See Also
DataColumn.labelField
DataColumn.lookupDisplay
GridDataSet.onRowUpdated
GridDataSet.onRowInserted
GridBase.onEditCellUpdated
数据查找概述
CalculatedColumn
Examples
数据查找
衍生字段
计算列