Save sort order or sort attribute in datagrid

I have a datagrid with multiple columns. The user is able to sort on every column they see using default datagrid sorting. Is it possible to save the sort order or the sorting attribute from the users input? I want to use it later on from the detail page to go to next or previous item from that same order.
2 answers

You will need some Javascript to make this happen. A JavaScript action call from a nanoflow might be a good way to execute this. So, on the page you’d have a button that calls a nanoflow, and that nanoflow would call a JavaScript action. Here’s what the JS action would need to do:

  1. Find the data grid DOM elements on the page
  2. Get a reference to the actual data grid widget object
  3. Get the current sorting setting on the data grid as a string
  4. Return that string


The code would need to look like this (note: this code is not fully tested but worked from my browser console):

// input parameter gridClass: a string matching a CSS class applied to the data grid on the page

var dgNode = document.getElementsByClassName(gridClass)[0];
var dg = dijit.registry.byNode(dgNode);
return JSON.stringify(dg._dataSource._sorting);
// outputs a string that looks like this:
// [["ShortDesc","asc"],["Price","asc"]]


(sorry about the formatting above… something is up with the code editor)



Hi Nick,

This is not possible using out of the box functionality. You will have to create custom functionality to achieve this. 


Couple of options that I can think of are (not sure if it works but may need some trails)

  1.  Custom logic / functionality
    • Create a SortingHelper entity and all the sort columns as attributes, associate this entity to your main entity and user account.
    • Add SortingHelper entity as a context entity of the page and retrieve data grid as association (create or retrieve this SortingHelper entity and associate it to a user in the microflow that opens this page).
    • Add custom button above required columns of data grid to sort (style them accordingly)
    • Add onchange event on each sort button and apply logic to retrieve and sort based on user selection, set SortingHelper_YourMainEntity association and persist the user selection. 
  2. Look into creating custom widget similar to data grid that includes all your requirements can be another option.


Hope this helps!