In Add/Edit pages update Lookup Table Select2 control at runtime

Hi. I have two tables (it is an example, my needing is more complex):
reports - ReportID, Country, CustomerID…
customers - CustomerID,Name,Country, …
In reports the CustomerID is setup with customers lookup table as usual.When I ADD/EDIT a new report I want to select the Country, and then filter the customers lookup table by that country.
But I don’t want to use dynamic selection, because, for example, I want to show the customer of that country and also the customers which don’t have any country setup.Is there any simple way to do this via javascript client code? The lookup_selecting filter is ok but it runs before outputting the page, while I need to customize the lookup table at runtime.I can use the the client side events to intercept a field modification, and then what code can I use to rebuild the reports.CustomerID select2 list calling internal apis?

Use the filter lookup table settings… there is an example when you set it up

but the “lookup table” filter is evaluated server-side at the page rendering time, and not every time the control is opened by the client, isn’t it?

Read Ajax by API and Client Scripts

Ok thank you. What about filling

Ok thank you.
In the example we can fill an INPUT control as written: $(“#x_UnitPrice”).val(row[“UnitPrice”]);
What about filling select2 control?

It should be similar. Just trigger the change event after update.