Here’s some example code that pulls a sort field from the URL querystring and substitutes it into the request for the list data, so that the net effect is that you can load mysite.com/listpage?sortingField=Email
and the list block on that page will sort by the Email
column instead of whatever was originally specified in the list block.
<script>
const urlParams = new URLSearchParams(location.search);
const sortingField = urlParams.get('sortingField');
if (sortingField) {
(function(send) {
XMLHttpRequest.prototype.send = function() {
if (typeof arguments[0] === "string") {
var b = JSON.parse(arguments[0]);
b.sortingOption.sortingField = sortingField;
const body = JSON.stringify(b);
arguments[0] = body;
}
send.apply(this, arguments);
};
})(XMLHttpRequest.prototype.send);
}
</script>
Note: the data will not display if the value of the sortingField
querystring parameter is not a valid field name.