Forum Discussion
FICO
6 years agoCommunity Manager
vdl-table default column sort
vdl-table is sorted ascending by the first column by default and the user can easily change this by clicking the column they want to sort by, but how can I change the default sort so all users initial have the table sorted by the n-th column? In other words, how can I set the underlying Datatables.js "order" parameter?
3 Replies
- FICOCommunity Manager
Alex,
You can use the aaSorting option to change the default sort.
function ascSort(tableOptions) { tableOptions.overrides.aaSorting = [[0, 'asc'],[1, 'asc']]; return tableOptions; } <vdl-table modifier="=ascSort"> <vdl-table-column entity="TestArray"/> </vdl-table>You only need to specify the columns you want to sort in the aaSorting definition.
If this is a table created with vdl-repeat then count the columns in what you see in the UI and use that.
- FICOCommunity Manager
Thanks @Libin Varghese, I've tried implementing that but don't see the sort change. Looks like the syntax is from legacy Datatables.js (https://legacy.datatables.net/ref). I think the latest FICO Insight uses a newer Datatables.js version with the 'order' syntax rather than 'aaSorting'. Making that one change to your ascSort function worked for me.
- FICOCommunity Manager
You are right. The 'aaSorting' was for the older VDL version 3.1. For the latest version you do need to use 'order'. Here is the modified code that should work.
function ascSort(tableOptions) { tableOptions.overrides.order = [[0, 'asc'],[1, 'asc']]; return tableOptions; } <vdl-table modifier="=ascSort"> <vdl-table-column entity="TestArray"/> </vdl-table>By default, Insight saves the state of the Datatable. If a user changes the sort and later comes back to the view, they would see the same sort as they set the last time. To turn this off, add the below override as well.
tableOptions.overrides.stateSave = false;
Related Content
Related Content
How to refresh vdl-table in JavaScript after adding a new row?
I want to replace the +- button coming with the addrow-autoinc option for vdl-table because we need to perform certain value changes when a new row is added. I think I managed in my JavaScript code (...3 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum1 unread comment1 unread0Views0likes1CommentIs there a way to export a multi-scenario VDL table?
Hello, One can create a VDL table containing data from several scenarios with: <vdl-table> <vdl-table-column entity="Entity" vdl-repeat="=s,i in scenarios" scenario="=i" head...4 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum2 unread comments2 unread0Views0likes2CommentsFilter vdl-table display to nonzero rows in FICO Insight application
This FICO Xpress Optimization forum might not be the right area for this question, but I don't see a forum for FICO Insight. I have a FICO Insight application that displays a Mosel entity on the...8 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum1 unread comment1 unread0Views0likes1Comment