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

Foreign key filter value as default value for new row

1 Answer 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Robert Madrian asked on 03 Mar 2020, 11:58 AM

Hello,

How to set the Foreign key filter value as default value for a new row?

If I have filtered my grid (see picture) and I click add new I want to have that filter value in my dropdownlist of the new row as the default value...

robert

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Silviya Stoyanova
Telerik team
answered on 06 Mar 2020, 12:41 PM

Hello, Robert,

Thank you for the provided screenshot.

Setting a default value for a field could be done within the dataBinding event handler of the Grid. You could check if the filter and add record actions are applied, as well as if the filtered column is the foreign key column. Then with the set() method of the observable set the filtered value.

dataBinding: function(e) {
              var filter = this.dataSource.filter();
              if(filter && e.action === "add"){
                if (filter.filters[0].field === "CategoryID") {
                  e.items[0].set("CategoryID", filter.filters[0].value);
                }
              }
            }
I have prepared a dojo example for your convenience. 

Let me know if that is a working solution for your case.

 

Regards, Silviya Stoyanova Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Grid
Asked by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Answers by
Silviya Stoyanova
Telerik team
Share this question
or