【问题标题】:Is there a way to override the default sorting behavior in JQGrid?有没有办法覆盖 JQGrid 中的默认排序行为?
【发布时间】:2012-09-12 19:48:11
【问题描述】:

我正在使用 JQGrid 4.4.0,我想覆盖整数排序方式的默认行为。我可以通过将每个colModelsorttype 属性设置为一个函数而不是文字'int' 来实现这一点。

不过,我想知道,有没有一种方法可以对我的 JQGrid 配置进行全局更改,如 example here 所示?

【问题讨论】:

    标签: sorting jqgrid


    【解决方案1】:

    您可以做的是使用colModeltemplate 属性或使用jqGrid 的cmTemplate 选项为网格的所有列定义默认的sorttype 属性。如果您在$.jgrid.defaults 中设置cmTemplate 选项,您将更改所有网格的所有列的默认sorttype 属性:

    $.extend($.jgrid.defaults, {
        cmTemplate: {
            sorttype: 'int' // you can use functions in the same way
                            // to define custom sorting
                            // see https://stackoverflow.com/a/5296935/315935
                            // for the code example
        }
    });
    

    查看the answer 了解更多详情。例如,如果您想从the answer 定义自定义排序功能

    【讨论】:

    • @TheDavester:不客气!我建议您使用cmTemplatetemplate。这些选项可以减少代码,使其更具可读性和可管理性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 2010-09-24
    相关资源
    最近更新 更多