Hi,
I have a combobox and I want to set to default value while adding a new row. Adding new row is also custom functionality.
Thanks
Ravi
Hello Indra,
I have been looking into your question and there are two approaches to have a default value in the given cells that you want when adding a new row according to your custom logic.
What I suggest as a first approach is to use the DefaultValue property of ColumnSettings when initializing the Updating feature of the igGrid. As in the given DefaultValue property you enter the value according to the datatype of the column, in this way when adding a new row, you will have initialized default values in the given cells of the given column.
.Features(features => { features.Updating() .ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("Name").DefaultValue("John"); settings.ColumnSetting().ColumnKey("Country").DefaultValue("USA").EditorType(ColumnEditorType.Combo).ComboEditorOptions(options => { options.DataSource(Model.Countries); options.TextKey("Value"); options.ValueKey("Value"); }); }); })
As a second approach, you can use the EditRowStarted event from GridUpdatingClientEvents by adding it to the initialization of the updating feature with AddClientEvent. After that you will enter a function name and in a script tag you will create the function itself. In the given function, you will check whether you are currently adding a row and if so, you will take the given editor according to the column key and set its value on this editor, as for the igCombo this is done with an index option and setting a value.
.Features(features => { features.Updating().AddClientEvent(GridUpdatingClientEvents.EditRowStarted, "editRowStarted"); }
<script> function editRowStarted(event, ui) { if (ui.rowAdding) { var editorCountry = $(ui.owner.editorForKey("Country")); editorCountry.igCombo("index", 1); var editorName = $(ui.owner.editorForKey("Name")); editorName.igTextEditor("value", "John"); } } </script>
The described scenario could be observed here:
In addition, I have prepared small sample illustrating this behavior which could be found attached here. Please test it on your side and let me know how it behaves.
3362.igGridComboBoxDefaultValue.zip
If you require any further assistance on the matter, please let me know.
Regards,
Georgi Anastasov
Entry Level Software Developer
Infragistics