Foreign key filter value as default value for new row

2 posts, 1 answers
  1. Robert Madrian
    Robert Madrian avatar
    227 posts
    Member since:
    Apr 2003

    Posted 03 Mar 2020 Link to this post

    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

     

  2. Answer
    Silviya Stoyanova
    Admin
    Silviya Stoyanova avatar
    66 posts

    Posted 06 Mar 2020 Link to this post

    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.
Back to Top