I have spent many hours to try to write a script which allow me to do the following :-
Currently i have a Discussion Board list which contain many items. where inside my site home page i added a new App Part representing the Discussion Board list.
Now i edit the app part setting and i select the "Subject" as the view.
So the final result i got is as follow. where there are links named; Recent, What's hot, My discussions... and inside the list menu i got links named; unanswered question, answered questions and Featured, as follow:-
Now i tried to find a way to set the default view for the app part to be "Featured" instead of "Recent".. but seems inside the app part setting we can not have these settings.
Now i already know that inside the App part there is a view named "Featured Discussions", but this view will only show the discussion item title and created by, without showing the number of replies or the number of likes..so that why i need to use the "Featured" link inside the "Subject" app part view.
so i tried this script to mimic clicking on the "..." link >> then clicking on the "Featured" link.
At first i thought the script worked well. but seems with some extra testing it did not, as currently i am facing these issues:-
on google chrome, Firefox and safari the script will work well. where when i first visit the page the list menu will open and the "Featured" view will be selected automatically. but when i open many tabs and refresh them all (where the response time will increase), then on some tabs i have noted that either the list menu is shown without selecting the "Featured" link (as shown in the above picture). and on other tabs the app part will be rendered as white area!!.
now on IE (currently i am using IE 11), the situation was as follow:-
- If i do a hard refresh for the page (CTRL + F5), the list menu menu will be shown, but the "Featured" link will not get clicked.
- If i access the page without doing a hard refresh (CTRL + F5) the script will not have any effect... even the list menu will not get shown.
Now I think that the issue i am facing is that the script will be accessing some components/markups that have not been rendered yet. due to performance delay or due to having 2
.trigger('click'); where one is depending on the other... so i am not sure if i can modify my script to work on a more robust way? and to eliminate the browser differences and performance issues which are breaking the script...
now based on @Aveenav reply, i added the following script inside a script editor web part:-
but this did not have any effect and still the Recent link will be selected. also i should mention that inside the page i have added 2 app parts for the Discussion Board list. now i need the first app part to have the "Featured" as the default , while for the other app part to keep the "Recent" as the defualt.. Thanks