Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2165
New row default values
posted

How to set default values for the new rows? I have a two level grid and I want to set default values for first row level. The first time the user adds a new row the cells should have empty values but when user adds more rows (first level rows) I want to set the same cell values (not all cells) of the last added row. Something like this:

$(document).delegate("#Grid", "iggridupdatingeditrowstarted", function(evt, ui) {

   newRowCellA = valueofCellAOfLastAddedRow;

   newRowCellB = valueofCellBOfLastAddedRow; // and so on.

}

I am not sure iggridupdatingeditrowstarted is the best event to work with but user should be able to abort (ESCAPE) the new row so it will not be part of the transaction.

By the way, cells are ColumnEditorType.Combo.

  • 17590
    Verified Answer
    Offline posted

    Hello Luis,

    Thank you for posting in our community.

    What I can suggest for achieving your requirement is setting the default editor`s values in the editRowStarted. In this event you will ensure that all the editors are created and there are two scenarios:

    -if you would like to select a value form the combo for default value. In this scenario the  selectedItems option could be used in order to set the selected items. For example:

    editRowStarted: function (evt, ui) {


    if (ui.rowID == -1) {


    var editorID = ui.owner.editorForKey("ID");

    var editorName = ui.owner.editorForKey("Name");

    var editorProductNumber = ui.owner.editorForKey("ProductNumber");

    $(editorName).igCombo("option", "selectedItems", [{ index: 1 }]);

    $(editorProductNumber).igCombo("option", "selectedItems", [{ index: 1 }]);


    }}

    -if you would like to use a custom value for default you should enable allowCustomValue option of the editors and use the text property. For example:

    editRowStarted: function (evt, ui) {


    if (ui.rowID == -1) {

    var editorID = ui.owner.editorForKey("ID");

    var editorName = ui.owner.editorForKey("Name");

    var editorProductNumber = ui.owner.editorForKey("ProductNumber");

    editorName.igCombo("option", "text", "");

    editorName.igCombo("option", "text", "Name12345");

    editorProductNumber.igCombo("option", "text", "");

    editorProductNumber.igCombo("option", "text", "prductNumber12345");

    }}

    I also made a small sample illustrating my suggestion and I am attaching it for your reference.

    I hope it helps you achieve your requirement,

    Please let me know if you need any further assistance with this matter.

    igGridAddNewRowDefaultValues.zip