Dynamically change datasource for SPDataTable Control

I am trying to figure out the best way to upload documents to different document libraries in SP2019-onpremises such as related department documents goes different docLibrary.
I currently have a form that saves documents in Docs library under folders related to each department. I used js to create folders and subfolders when a new item created and dynamically get - add document content from related folder by modifying folder/subfolder value in control settings of SPDataTable control. I've seen a post previously that dynamically change folders/subfolders in js and used that.

However, 1)for managing permissions on doclib level not on folder level and 2) In feature, not to stuck with SP view performance limitation to get and display documents related docs from more than 5000 docs in one doclib;
I am looking for a way to manupulate Datasource dynamically to change document library (ie dept1, dept2...etc). based on department selection field value in the form.

I appreciate if there are any methods you could suggest...

Hello @Levent_Acar,

You can add multiple List or Library controls connected to different libraries, and show/hide them depending on the department that users select in a drop down.