How to pass additional parameters to the JsGrid custom sortStrategies function?

316 Views Asked by At

I'm using JsGrid v1.5.3 and i successfully created a field like this using JsGrid

{
    name: "1_price",
    className: 'wordwrap',
    title: 'Test Price',
    type: "text",
    width: 75,
    filtering: false,
    sorting: true,
    sorter: 'priceSorter',
    itemTemplate: function(value, item) {
        if (typeof value === 'undefined') value = '';
        if (item && item.hasOwnProperty('is_sold_out') && item.is_sold_out == 1) {
            return '<span class="sold-out-strikethrough">' + value + '</span>';
        } else {
            return '<span>' + value + '</span>';
        }
    }
} 

then i tried to create the custom sorter function like this:

window.jsGrid.sortStrategies.priceSorter = function(price1, price2) {
   console.log(arguments)
}

from the console.log(arguments) it only send 2 parameters value, how can i extend it so i can receive another parameters, for example the additional parameters is the field name (1_price):

window.jsGrid.sortStrategies.priceSorter = function(price1, price2, fieldName) {
   console.log(arguments)
}
1

There are 1 best solutions below

0
On

You can send multiple parameters by defining them in an Array or JSON object.

window.jsGrid.sortStrategies.priceSorter = function({price1:price1, price2:price2, fieldName:fieldName}) {
   console.log(arguments)
}

Or

var params = {price1:price1, price2:price2, fieldName:fieldName};
window.jsGrid.sortStrategies.priceSorter = function(params) {
   console.log(arguments)
}

Or

var params = [price1, price2, fieldName];
window.jsGrid.sortStrategies.priceSorter = function(params) {
   console.log(arguments)
}