Custom Sort List/Library Control button

Hello Plumsail,

Is there a way to add a button in the list/library control where users can click and sort the list data from Descending to Ascending.

The list view shows all the recent records at the top and the old records appear at the bottom which can cause issues.

Ideally, I want to sort by the "Created Date" field in SharePoint.

I'm aware of clicking the field name will sort it but I want to have a button on the control so that it's more clearer to the users that they have this option.

Hope that makes sense!

Many thanks!

Hello @DryChips,

You can add buttons to the toolbar of the control to sort columns, see code example:

//add new buttons
var buttonAscending = {
	text: 'Sort Ascending',
	class: 'btn-secondary',
	visible: true,
	icon: '',
	iconType: 0,
	click: function() {
    //sort Title column ascending
	fd.control('ListOrLibrary1').widget.dataSource.sort({
		field: "Title",
		dir: "asc"
	});
	}
}
fd.control('ListOrLibrary1').buttons.push(buttonAscending);

The code to sort column descending:

fd.control('ListOrLibrary1').widget.dataSource.sort({
	field: "Title",
	dir: "desc"
});
1 Like