Sorting LFD based on a custom calculation?

For my app I have a common data source that all users will read from. They will each sort it differently depending on a calculation (in JavaScript) involving both values from the data source and entered by the user. I’m not seeing a way to sort the list by anything other than an existing column in the data source.

I’m trying to avoid using logins since they aren’t necessary for most of what I want to do and I want to avoid any barriers to adoption that I can.

What’s my best strategy here?

Hi Steven,

You can use this: List (from data source) | Fliplet Developers Documentation with our LFD to write custom code to sort the entries based on a custom sort order.

Just sort the options.records based on the sort you want it to and it will be displayed in the LFD.

Thanks,
Deb

Thank you so much, I was getting close to that answer but hadn’t nailed that particular hook yet. I do need help with how to define this:

config (Object) Configuration used to initialize the component.

-David

Hi Steven,

If you already have an LFD component on the screen you do not need to define that. That is an Object that is returned to you by the LFD when the hook runs.

If you would like to use this hook to sort an LFD then you need to do something like this:

Fliplet.Hooks.on('flListDataBeforeRenderList', function(options){
    options.records = options.records.sort(function(a, b) {
        //This sorts by the column Email in the ascending order. 
        return order.indexOf(a.data.Email) - order.indexOf(b.data.Email);
      });
})

You need to change Email above to the column you want to sort by.

Here are some examples on how to sort a JSON array based on custom conditions.

Thanks,
Deb

1 Like