- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 demo website 中使用了 q jqgrid,'groupd header row config' 版本的 jqgrid 。
它生成网格。但假设 senario 其中 Notes
列可以包含数字和字符串,因为某些行中有数字,某些行中有字符串字符,排序会被关闭,并且它仅适用于字符串字符。
场景:假设表格有五行,Notes
列有以下五行数据:
this is good
123
number 123 number
>123.23
<=222.88
我已使用 sort:true 将排序选项添加到 colModel 中,但这仅在注释列具有所有行的字符串字符时才进行排序,但如果它具有数字行和字符串字符行的组合,则不会进行排序。我该如何解决这个问题?
最佳答案
jqGrid 包含多种自定义排序的可能性。首先值得一提的是,只有当您使用 datatype: "local"
或某些远程 datatype
("json"
) 时,以下所有可能性才有意义code>、"jsonp"
、"xml"
) 与 loadonce: true
结合使用。在最后一种情况下,第一次从服务器加载数据后,数据类型
将更改为“local”
。
要对列中的本地数据进行排序,jqGrid 必须比较值。它执行一些初步步骤。首先,如果用项目填充数组,它将内容从一列映射到 rowid。因此你可以定义
sorttype: function (cellValue, item) {
return cellValue; // another value as cellValue can be returned
}
它为您提供了第一种自定义排序方式。例如,您可以使用 RegEx 从 callValue
中提取信息的“数字”部分,并从 sorttype
返回它(您可以在 colModel 中定义)
列注释
)。请参阅the old demo为 the answer 创建了解更多详情。
第二种方式:在colModel
中定义sortfunc
回调。回调有原型(prototype)
sortfunc: function (a, b, direction) {
// should return 0, 1 or -1
}
在旧版本的 jqGrid 和
sortfunc: function (a, b, direction, aItem, bItem) {
// should return 0, 1 or -1
}
在 free jqGrid 。 sortfunc
允许您实现您需要的任何自定义排序行为。请参阅the demo为 the issue 创建代码示例。
关于javascript - 如何对具有多种类型值的列进行排序? [特兰德JQGrid 4.6],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40199651/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
正如您在 this travis.yml 中看到的那样文件,我的代码依赖于一些第三方库,我在构建项目之前将它们安装在远程系统上。 Travis 每次推送提交时都会下载并构建这些库,这可以避免吗?我的意
我是一名优秀的程序员,十分优秀!