如何将其他参数传递给JsGrid自定义sortStrategies函数?

问题描述

我正在使用JsGrid v1.5.3,并且使用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>';
        }
    }
} 

然后我尝试创建自定义排序功能,如下所示:

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

console.log(arguments)仅发送2个参数值,我如何扩展它以便可以接收其他参数,例如,其他参数是字段名称(1_price):

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

解决方法

您可以通过在Array或JSON对象中定义多个参数来发送多个参数。

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

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

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