jquery - jQuery数据表:排序后用行索引重写每一行的标题
问题描述
感谢 Andrew James,我能够将行的索引写入行的 title 属性。现在我有这段代码在每次排序后都会执行,但我正在寻找一种美化代码的方法
如果没有人可以,那么这可以作为其他人的解决方案,因为它有效
干杯
var table = $(".table").DataTable(...);
//jquery code to rewrite the row index number to each row title after sorting
function writeRowIndex() {
var rowIdx = 1;
table.rows().every(function (rowIdx) {
$(this.node()).attr('title', rowIdx);
rowIdx++;
});
}
//call the function on loading the page;
writeRowIndex();
//calling function after each sorting event
var headers = table.columns().header().toArray();
$(headers).on('click', function () {
writeRowIndex();//call existing function
});
解决方案
推荐阅读
- python - Python Web 抓取 - 保存变量
- python - Python比较不同数据类型的排序
- c# - Unity多点触控无法达到其方法
- resttemplate - 线程“主”org.springframework.web.client.HttpServerErrorException$InternalServerError 中的异常:500
- pycharm - 运行 Pycharm 的控制台大小
- airflow - 最佳数据管道框架
- python-3.x - 如何为返回json和字符串的方法创建responsr对象
- ping - 同一家庭网络中的 Ubuntu 和 Mac 找不到彼此
- ios - 在 SwiftUI 中滚动时隐藏视图的动画
- ruby - 如何从 ruby 中的 ruby Money::Currency.all 获取 iso 代码和名称