Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    I’m sorry, but has not been included a description of the equation.

    For example, if you want to display a list of numbers separated by comma, ordered decreasingly, and these numbers are the values of fields: fieldname1, fieldname2, and fieldname3, you can associate to the calculated field the following equation:

    (function(){
    var list = [fieldname1, fieldname2, fieldname3];
    list.sort(function(a, b){return b-a});
    return list.join(',');
    })()

    and that’s all.
    Best regards.

    Thread Starter uafinsee

    (@uafinsee)

    Sorry, I didn`t clarify my question.
    The equations for calculation are complex including numerous “if” statements and multiplications.
    Example is here: finsee.com/test

    At the end users see a result like this (name of the bank – amount of money)

    Bank A 1500
    Bank B 1800
    Bank C 1600

    Can I sort it the following way:

    Bank B 1800
    Bank C 1600
    Bank A 1500

    So that the name of the field will appear before the number and they would appear one in a row?

    Plugin Author codepeople

    (@codepeople)

    Hi,

    I’m not sure how are you creating the list, but you can create an object with the banks, where the attribute’s name is the number, for example:

    var list = {
    1500: 'Bank A 1500',
    1800: 'Bank B 1800',
    1600: 'Bank C 1600'
    };

    and edit the equation I sent you previously for ordering the results:

    (function(){
    var list = {
    1500: 'Bank A 1500',
    1800: 'Bank B 1800',
    1600: 'Bank C 1600'
    };
    
    var keys = Object.keys(list);
    var result = [];
    
    keys.sort(function(a, b){return b-a});
    
    for(var i = 0; i < keys.length; i++)
    {
    result.push( list[ keys[i] ] );
    }
    return result.join(',');
    })()

    and that’s all.
    Best regards.

    Thread Starter uafinsee

    (@uafinsee)

    Thank you for your suggestions.

    I wonder if there is any quick fix to a more complex problem?

    calculator

    When a user clicks “calculate” button she sees a list of fieldsets. All of them have 4 columns, that coud be named textarea1, calc_field1, calc_field2,textarea2.

    calc_field1 and calc_field2 are calculated fields based on users entering loan amount and term and selecting few options.

    Is it possible to sort fieldsets based on the values of calc_field2 in each of the fieldsets?

    So that first the user will see a fieldset with lowest amount of calc_field2, then second lowest etc.
    Just like you can sort hotels based on price on booking.com

    Plugin Author codepeople

    (@codepeople)

    Hi,

    There is not an operation in the plugin to organize the fields in the form at runtime, however I can recommend you an alternative.

    For example: suppose there are three fieldsets, each of them with one calculated field inside whose names are: fieldname3, fieldname4, and fieldname5, respectively

    First, select the fieldset fields, and assign to each of them an unique class name, for example: my-container-a, my-container-b, and my-container-c respectively.

    Second, insert a calculated field at the end of the form (if it is used only as an auxiliary field and is not important in the form’s interface, tick the checkbox: “Hide Field From Public Page”), and enter as its equation, the following one:

    (function () {
    	var list = {
    		fieldname3 : jQuery('.my-container-a'),
    		fieldname4 : jQuery('.my-container-b'),
    		fieldname4 : jQuery('.my-container-c')
    	},
    
    	var keys = Object.keys(list);
    	keys.sort(function (a, b) {
    		return b - a
    	});
    
    	var tmp;
    	for (var i = 0; i < keys.length; i++) {
    		if(typeof tmp == 'undefined')
    		{
    			tmp = i; continue;
    		}
    		list[keys[i]].after( list[keys[tmp]]);
    		delete list[keys[tmp]];
    		tmp = i;
    	}
    })()

    And that’s all.
    Best regards.

    Thread Starter uafinsee

    (@uafinsee)

    Thank you for very fast response.

    I have assigned classnames to my fieldsets from cont01 to cont21 by writing these names in “Add Css Layout Keywords”

    Then I created a calculated field at the end of the form with the equation in which I modified numbers of fieldnames and names of the classes.

    But, unfortunately it didn`t work. The modified form is on https://finsee.com/test

    I even tried this solution on a new and very simple form also without any result.

    Could you plese point me in a direction where I could have made a mistake in implementation of this solution?

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Please, replace your equation by the following one:

    (function () {
    	var list = {};
    	list[fieldname94] = jQuery('.cont01');
    	list[fieldname101] = jQuery('.cont02');
    	list[fieldname111] = jQuery('.cont03');
    	list[fieldname22] = jQuery('.cont04');
    	list[fieldname14] = jQuery('.cont05');
    	list[fieldname15] = jQuery('.cont06');
    	list[fieldname21] = jQuery('.cont07');
    	list[fieldname77] = jQuery('.cont08');
    	list[fieldname152] = jQuery('.cont09');
    	list[fieldname16] = jQuery('.cont10');
    	list[fieldname50] = jQuery('.cont11');
    	list[fieldname82] = jQuery('.cont12');
    	list[fieldname160] = jQuery('.cont13');
    	list[fieldname176] = jQuery('.cont14');
    	list[fieldname187] = jQuery('.cont15');
    	list[fieldname8] = jQuery('.cont16');
    	list[fieldname207] = jQuery('.cont17');
    	list[fieldname218] = jQuery('.cont18');
    	list[fieldname70] = jQuery('.cont19');
    	list[fieldname232] = jQuery('.cont20');
    	list[fieldname55] = jQuery('.cont21');
    
    	var keys = Object.keys(list);
    	keys.sort(function (a, b) { return b - a	});
    
    	var tmp;
    	for (var i = 0; i < keys.length; i++) {
    		if(typeof tmp == 'undefined')
    		{
    			tmp = i; continue;
    		}
    		list[keys[i]].after( list[keys[tmp]]);
    		delete list[keys[tmp]];
    		tmp = i;
    	}
    })()

    Best regards.

    Thread Starter uafinsee

    (@uafinsee)

    Thank you a lot for your advise.

    For those who would strugle with this issue in future, I suggest changing the line

    list[keys[i]].after( list[keys[tmp]]);

    with the following:

    list[keys[tmp]].before( list[keys[i]]);

    Then it works with more than 3 fieldsets.

    Took me few days to figure that out ??

    Now my opinion about capabilities of this plugin has risen even further.

    Plugin Author codepeople

    (@codepeople)

    Hi @uafinsee,

    Thank you very much for sharing your solution.

    Best regards.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sorting results’ is closed to new replies.