Advanced Sorting
Overview
Reusable widget to encapsulate the math required to manually do sorting. Most useful when getting data from an API that allows sorting or writing SQL / OQL queries (e.g. https://cars.com/users?sort_by=year&order=desc).
Tip: Need pagination too? Check out Advanced Pagination. (GitHub) (Mendix Marketplace)
Need selection too? Check out Listview Selection. (GitHub) (Mendix Marketplace)
Documentation
For a better view of the documentation see the GitHub Readme
Advanced Sorting
Reusable widget to encapsulate the math required to manually do sorting. Most useful when getting data from an API that allows sorting or writing SQL / OQL queries (e.g. https://cars.com/users?sort_by=year&order=desc).
Tip: Need pagination too? Check out Advanced Pagination. (GitHub) (Mendix Marketplace)
Need selection too? Check out Listview Selection. (GitHub) (Mendix Marketplace)
Features
- Offers Headers and Dropdown sorting methods
- Drag and drop method of setting sorting attributes
- Ability to customize the icons displayed
- Accepts a Sort Attribute string and a Sort Ascending boolean
- Ability to use any Mendix content for the header
- Ability to configure your own list of dropdown values
Limitations
- N/A
Usage
- Create a non-persistent entity called Pagination with at least SortAscending (boolean) and SortAttribute (string). Ideally this should be in it's own module for easier importing and exporting to new projects!
- Create a non-persistent entity specific to your grid (i.e. SearchVehicles), have it inherit Pagination and give it an association to System.Session
- Create a Microflow called ACT_RefreshPagination with a Pagination parameter, add a change object activity, and set the change object activity to refresh in client
- Create a Microflow called DS_CreateRetrieve_{SpecificEntityName} that will check the System.Session for an existing {Specific Entity Name} object. If an object is found, return it; otherwise create a new one (don't forget to set the $currentSession in the Create Object activity)
- Setup your page similar to how you see below with the widget above the list view. These should be inside a data view with datasource DS_CreateRetrieve_{SpecificEntityName}.
- In the Advanced Sorting widgets, go to the Data tab and set the Refresh Action with ACT_RefreshPagination, the Sort Attribute, and the Sort Ascending
The remaining steps depend on whether you want a dropdown or a clickable grid header.
Header
7a. In the Advanced Sorting widgets, go to the General tab and set the Attribute Name as the name of the attribute you want sorted. This must match the name of the attribute exactly and is case sensitive. In this example, I want to sort the Year attribute from the Vehicles entity (step 2).
Static Dropdown
7b. Static dropdown lets you create a list of dropdown options that act as pre-sets of sorting options. Add a dropdown value and set all of the fields. Caption is the literal text that will appear as an option in the dropdown. Sort Ascending and Attribute Name are the values that will be set to the pagination object's SortAttibute and SortAscending attributes once the option is selected. Default determines if the option is selected automatically. If no default is specified, the widget will use the first option in the list.
Dynamic Dropdown
7c. Dynamic dropdown lets you create the options that appear in the dropdown via a Microflow. Start by creating a new non-persistent entity called SortDropdownValue with the following attributes.
8c. Next, create a Microflow call DS_SortDropdownValues that returns a list of SortDropdownValue objects.
9c. In the Advanced Sorting widgets, go to the Dynamic Dropdown tab and set the Dynamic Data Source as the new Microflow and the rest of the settings as the attributes from the SortDropdownValue object.
Note: If you need to sort an attribute across an association, you must include the full database path. For example, if I need to sort the Name attribute on the Make entity (step2).
Demo project
https://widgettesting105-sandbox.mxapps.io/p/advanced-listview-controls
Issues, suggestions and feature requests
https://github.com/bsgriggs/mendix-advanced-sorting/issues
Development and contribution
Benjamin Griggs