Hi Palsaran,
In onpress function, you have to check the visibility of all the columns(n number of columns). If the column is visible then check the checkbox otherwise don't check.
You can get the visibility of column by using column id.
What I understand is the purpose of dialog window is to make the column visible or invisible.
If that is the case, use showColumnVisibilityMenu:true to achieve this.
On click of column, it will display number of columns in the table, based on selection it will make visible or invisible.
For more details check this link