Cora Knowledge Center

Support

Catch a Grid Insert Event to Update a Combo Box

This sample shows how to all the required steps to catch a grid insert event and update a combo box. Add the samples to the relevant code.

  • Catch a grid insert event
  • Find a combo box
  • Check that the combo box has a value 
  • Update another combo box in the inserted line with the first combo box value if the second combo box is empty

Grid

<ClientSettings>
  <ClientEvents OnCommand="RaiseCommand" />
</ClientSettings>

JavaScript

function RaiseCommand(sender, eventArgs) {
     //retrieve the current commandName and commandArgument
     var result = String.format("CommandName: {0}, CommandArgument: {1}", eventArgs.get_commandName(), eventArgs.get_commandArgument());
     if (eventArgs.get_commandName() == 'PerformInsert') {
         var grid = $find(getClientIdById("Grid1"));
         var MasterTable = grid.get_masterTableView();
         var insertedItem = MasterTable.get_insertItem();
         var Rows = MasterTable.get_dataItems();
         var jComboTo = $sq("[id$='RCB_fldCascadeTo']")
         var jComboFrom = $sq("[id$='RCB_fldCascadeFrom']")
 
         if (jComboTo.length != 0) {
             var comboBoxTo = $find(jComboTo[0].id);
             var cascade_to_value = comboBoxTo.get_value();
             if (cascade_to_value == '' || cascade_to_value == null) {
 
                 var comboBoxFrom = $find(jComboFrom[0].id);
                 var cascade_from_value = comboBoxFrom.get_value();
                 var cascade_from_text = comboBoxFrom.get_text();
                 comboBoxTo.set_value(cascade_from_value);
                 comboBoxTo.set_text(cascade_from_text);
             }
         }
     }
}