javascript - jqgrid在排序时更改光标
问题描述
我想将光标更改为wait
用户单击列标题以对数据进行排序时(因为该过程需要几秒钟,在此期间没有任何变化)。
为此,我尝试更改事件cursor
中的 CSS 属性onSortCol
:
onSortCol: function (index, iCol, sortorder) {
$("body, .ui-jqgrid .ui-th-column > div.ui-jqgrid-sortable").css({'cursor' : 'wait'});
}
并在loadComplete
事件中将其改回:
loadComplete: function () {
$("body").css({'cursor' : 'default'});
$(".ui-jqgrid .ui-th-column > div.ui-jqgrid-sortable").css({'cursor' : 'pointer'});
}
但它不起作用。似乎浏览器在排序完成之前没有呈现光标。
知道如何进行吗?
解决方案
我最终得到了这个解决方案:
- 在 jqGrid 库中查找开始排序的调用
- 在此调用之前更改光标
- 设置超时以让浏览器有时间考虑更改
- 运行排序
- 恢复光标
这是在jquery.jqgrid.src.js
(版本 4.15.4)中完成的5729
:
if (iColByName != null) {
// the $("div", this)[0].id looks like "jqgh_" + p.id + "_" + colIndex (like "jqgh_list_invdate")
sortData.call(ts, $("div", this)[0].id.substring(5 + p.id.length + 1), iColByName, r, d, this, e);
}
我替换为:
if (iColByName != null) {
// the $("div", this)[0].id looks like "jqgh_" + p.id + "_" + colIndex (like "jqgh_list_invdate")
$("body").addClass('waiting');
setTimeout(() => {
sortData.call(ts, $("div", this)[0].id.substring(5 + p.id.length + 1), iColByName, r, d, this, e);
$("body").removeClass('waiting');
}, 50);
}
这里的 CSS 类waiting
取自这里:https ://stackoverflow.com/a/25207986/8790102
body.waiting * {
cursor: progress;
}
推荐阅读
- javascript - 调用函数时如何取消绘制矩形
- asp.net-core - Razor 视图中的 @code 标记引发编译器错误
- javascript - 根据 JavaScript 对象的结果显示/隐藏 div
- azure - Azure 服务总线:如何在订阅者出现故障时实现最终一致性
- javascript - 范围内的已定义变量未定义
- java - 将 txt 文件读入 ArrayList 的问题
- c - 为什么在 GCC 中错误使用 __attribute__((pure)) 没有给出警告?
- python - 在python中用分隔的双引号和布尔值解析json字符串表示
- jquery - 点击 GSAP 将卡片转回
- xamarin.android - 使用 TabLayout 时 ViewPager 不加载片段