This is a migrated thread and some comments may be shown as answers.

Grid with a custom DropDownList as an editor not working dataItem.set value

3 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Liton
Top achievements
Rank 1
Veteran
Liton asked on 23 Jun 2020, 02:19 PM

Dear Concern,

I'm trying to select frist value from dropdownlist if have only one value. I have grid Add row button. When I'm clicking on Add line button (please see attached image) grid creating one row job drop-down should automatically bind if job drop-down has one value.Please see the attached file. This will help users to fill the job dropdown more quickly (no need click on dropdown) if just one job in dropdown.

If only one job in dropdown and user clicks on Add Line, Make it so that the JOB# automatically fills. 

I'm trying below way but its not working. 

var dataItem = _getGridCurrentDataItem(PARTS_GRID_CONTROL_ID); 

if (jobs.length == 1) {                        
                        if (dataItem) {
                            dataItem.set("SerRecID", jobs[0]);                            
                        }
                    }

Thanks !

Liton

 

3 Answers, 1 is accepted

Sort by
0
Liton
Top achievements
Rank 1
Veteran
answered on 23 Jun 2020, 02:47 PM

Issue is in the validation. If i remove the validation then its work fine but I need validation also. How can I achieve that ? Please see the code below my validation code. Thanks !

model: {
                            id: "PartsUsedGuid",
                            fields: {
                                SerRecID: {
                                    from: 'SerRecID', type: 'string', defaultValue: '', validation: {
                                        custom: function (input) {                                            
                                            input.attr("data-custom-msg", "Please Select Job Id");
                                            console.log("ltnPartsUsedGuid");
                                            return input.val() != "" && input.val() != "0";
                                        }
                                    }
                                },

0
Liton
Top achievements
Rank 1
Veteran
answered on 23 Jun 2020, 03:15 PM

Issue is in validation, If i removed validation then its working fine but i need also validation. How can resolved this?

model: {
                            id: "PartsUsedGuid",
                            fields: {
                                SerRecID: {
                                    from: 'SerRecID', type: 'string',
                                    validation: {                                       
                                        custom: function (input) {    
                                            input.attr("data-custom-msg", "Please Select Job Id");
                                            console.log("ltnPartsUsedGuid");
                                            return input.val() != "" && input.val() != "0";
                                        }
                                    }
                                },
0
Alex Hajigeorgieva
Telerik team
answered on 25 Jun 2020, 10:20 AM

Hi, Liton,

The easiest way to achieve the desired result is to have a defaultValue in the data source schema model field.

It appears that you are using the MultiColumnComboBox, so I prepared this example for you:

https://dojo.telerik.com/@bubblemaster/AMURUGEL

fields: {
  SerRecID: {
        defaultValue: '49777', type: 'string',

On a side note, the field.from mapping is not necessary since the field is not a different one.

Let me know if you expected a different behaviour if you have more than one job options. An alternative could be to capture the beforeEdit event and assign the job value:

https://dojo.telerik.com/@bubblemaster/acevogog

 beforeEdit: function(e) {
  if (e.model.isNew()) {
       e.model.ProductName = "Alice Mutton"
  }
}

Regards,
Alex Hajigeorgieva
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Liton
Top achievements
Rank 1
Veteran
Answers by
Liton
Top achievements
Rank 1
Veteran
Alex Hajigeorgieva
Telerik team
Share this question
or