By default Action Grid initially sorts data as it is delivered from the data source. The user optionally can sort data as needed (First Grid)
Sometimes the desired sort order is not available from the data source. This can be overriden by adding query string parameters to the URL, but the URL used by a User is not always controllable.
In the second (Bs 3) and third (Bs 5) grid, the inital sort is set to Last Modified Date, Descending by adding the javascript function dnnsf.updateQueryStringParam(key, value) to the grid initialization. Any subsequent user selectable sorting will still be functional.
dnnsf.updateQueryStringParam(key, value)
Key = Query String Parameter Name
Value = Value to set the parameter to.
The Grid Initialization is located by managing the grid, then navigating to Settings, Advanced UI Setting, On Init Java Script, and adding these two lines of code.
** Bootstrap 3 / Bootstrap 5 update**
-- Bootstrap 3 --
dnnsf.updateQueryStringParam("sort669","LastModifiedDate");
dnnsf.updateQueryStringParam("sortdir669","desc");
The First Line Selects the column to sort on, the second the direction of sort.
Note the ID ( 669 ) of the Grid Control in the Key Names, this allows the parameter to affect only that specific grid on the page.
-- Bootstrap 5 --
With the Bs 5 views, the query string paramaters are handled differently. In Bs 3 the Sort parameter was named sort + id (sort669), in Bs 5 the parameter is named sort.
targeting is no longer done by appending the control ID. Instead a userdefined prefix (init) is placed in front of the parameter name (initsort). The prefix is entered in the Sync with URL settings.
dnnsf.updateQueryStringParam("initsort","LastModifiedDate");
dnnsf.updateQueryStringParam("initsortdir","desc");
The First Line Selects the column to sort on, the second the direction of sort.