SMART datagrid v.1 > Examples

Back  Forward

Label Field  Example

labelField is the simplest implementation type for Data Lookup. It will display the field value specified through labelField property rather than the original data field value in the column cells. 

In the grid below, "National currency" column specifies "country_currency" field as labelField

Grid - 1
rows

At this point, if editing starts after the initial load of the data set, appropriate synchronization may be needed, and you can change the value of label field in GridDataSet.onRowUpdated or onRowInserted event in the data set level, and change and proceed the value corresponding to label field within GridBase.onEditCellUpdated event to synchronize in the editing grid row. 

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));
        }
    }

In order to move labelField to work, DataColumn.lookupDisplay should be specified as true. And, you can also use Derived Fields to implement easily. 

View Source JSP 

See Also
DataColumn.labelField
DataColumn.lookupDisplay
GridDataSet.onRowUpdated
GridDataSet.onRowInserted
GridBase.onEditCellUpdated
Data Lookup Overview
CalculatedColumn
Examples
Data Lookup
Derived Fields
Calculated Columns