微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何将其他参数传递给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)
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。