SMART datagrid v.1 > Classes > GridDataSet

Back  Forward

DataLudi.GridDataSet.updateValues  method

Update the values of data row which matches the condition specified by parameter where with the values transferred by newValues

where can be Expression string or callback function. newValues is JSON object of containing the fields which would be changed. In the value of each field, it can specify callback function which returns field value. 

If checkDiff is true, it will update the row only when one or more field values are different by comparing the value of newValues with the existing field value. If strictDiff is true, it will compare with DataField.equalValues, sameValues. If noState is true, it will not change the state of data rows. 

function updateValues (where: String|Function, newValues: Object, checkDiff: Boolean, strictDiff: Boolean, noState: Boolean);
Returns
Void
Parameters
where - String|Function. Defaults to null.
newValues - Object. required.
checkDiff - Boolean. Defaults to false.
strictDiff - Boolean. Defaults to false.
noState - Boolean. Defaults to false.
Table-1  The variables which can be used in where discriminant
VariableExplanation
'row'The index of data row.
'values'The value of field. 'values[field]'. The field can be specified by field index or field name.
'state'The State of data row. CREATED is 'c', UPDATED is 'u', DELETED is 'd' CREATE_AND_DELETED is 'x'.
Code -1
    // Transfer the discriminant to where.
    dataset.updateValues(
        "values['flow'] == 'import'",   // where
        { amount: 100, active: false }, // newValues
        false, false, false);
    }
Code -2
    // Specify callback in where.
    dataset.updateValues(
        function (ds, row, values) {    // where
            retrun values[0] == 'import';
        },
        { amount: 100, active: false }, // newValues
        false, false, false);
    }
Code -3
    // Transfer the discriminant to field value.
    dataset.updateValues(
        "values['flow'] == 'import'",   // where
        {                               // newValues
            amount: 100, 
            active: function (ds, row, field) {
                if (ds.getValue(row, 0) == 'import') {
                    return true;
                }
                return false;
            }
        }, 
        false, false, false);
    }
See Also
onStatesChanged
onRowsUpdated
updateRows
Examples
Row Updating