jquery - jQuery Table Sorter - 无法让表格对表格的列进行排序(单元格值可以在排序前由 jQuery 动态更改)
问题描述
我有一个行表,最后一个单元格是或否。该列不响应排序,可以在更改排序顺序之前修改,但是没有排序发生。
我无法生成最小完整可验证示例,但我可以说初始化代码只是简单。
$(".tablesorter").tablesorter(); //this is inside a document.ready block
所有其他行都排序,但没有排序的那一行令人费解。
这是零配置吗?
我还尝试将上述初始化调用链接到:
$(".tablesorter").tablesorter({
textExtraction: 'complex',
headers: {
10: {sorter: 'text'} // 10 is the column number starting from the sortable columns
}
});
但不会发生任何变化。
我该如何解决?
解决方案
https://dotnetfiddle.net/MF18yG
控制器/视图模型
public class Row
{
public string Col1 { get; set; }
public string Col2 { get; set; }
public string Col3 { get; set; }
public string Col4 { get; set; }
public string Col5 { get; set; }
public string Col6 { get; set; }
public string Col7 { get; set; }
public string Col8 { get; set; }
public string Col9 { get; set; }
public string Col10 { get; set; }
}
public class Table
{
public IList<Row> Rows { get; set; }
}
public class HomeController : Controller
{
public ActionResult Index20()
{
var viewModel = new Table { Rows = new List<Row>() };
var row1 = new Row
{
Col1 = "Col1",
Col2 = "Col2",
Col3 = "Col1",
Col4 = "Col4",
Col5 = "Col5",
Col6 = "Col6",
Col7 = "Col7",
Col8 = "Col8",
Col9 = "Col9",
Col10 = "Yes"
};
var row2 = new Row
{
Col1 = "Col1",
Col2 = "Col2",
Col3 = "Col1",
Col4 = "Col4",
Col5 = "Col5",
Col6 = "Col6",
Col7 = "Col7",
Col8 = "Col8",
Col9 = "Col9",
Col10 = "No"
};
var row3 = new Row
{
Col1 = "Col1",
Col2 = "Col2",
Col3 = "Col1",
Col4 = "Col4",
Col5 = "Col5",
Col6 = "Col6",
Col7 = "Col7",
Col8 = "Col8",
Col9 = "Col9",
Col10 = "Yes"
};
var row4 = new Row
{
Col1 = "Col1",
Col2 = "Col2",
Col3 = "Col1",
Col4 = "Col4",
Col5 = "Col5",
Col6 = "Col6",
Col7 = "Col7",
Col8 = "Col8",
Col9 = "Col9",
Col10 = "No"
};
var row5 = new Row
{
Col1 = "Col1",
Col2 = "Col2",
Col3 = "Col1",
Col4 = "Col4",
Col5 = "Col5",
Col6 = "Col6",
Col7 = "Col7",
Col8 = "Col8",
Col9 = "Col9",
Col10 = "Yes"
};
viewModel.Rows.Add(row1);
viewModel.Rows.Add(row2);
viewModel.Rows.Add(row3);
viewModel.Rows.Add(row4);
viewModel.Rows.Add(row5);
return View(viewModel);
}
看法
@model WebApplication2.Controllers.Table
@using WebApplication2.Controllers
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index20</title>
@*https://mottie.github.io/tablesorter/docs/*@
<!-- choose a theme file -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.29.0/css/theme.default.min.css"
integrity="sha256-kZJ4kB78IbXuxMtCpmaXzii8vxEKtu8pjicH62E0/qM=" crossorigin="anonymous" />
<!-- load jQuery and tablesorter scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.min.js"></script>
<!-- tablesorter widgets (optional) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.widgets.min.js"></script>
<script type="text/javascript">
$(function () {
$("#myTable").tablesorter();
});
</script>
</head>
<body>
<div>
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
<th>Col4</th>
<th>Col5</th>
<th>Col6</th>
<th>Col7</th>
<th>Col8</th>
<th>Col9</th>
<th>Col10</th>
</tr>
</thead>
<tbody>
@foreach (Row row in Model.Rows)
{
<tr>
<td>
@row.Col1
</td>
<td>
@row.Col2
</td>
<td>
@row.Col3
</td>
<td>
@row.Col4
</td>
<td>
@row.Col5
</td>
<td>
@row.Col6
</td>
<td>
@row.Col7
</td>
<td>
@row.Col8
</td>
<td>
@row.Col9
</td>
<td>
@row.Col10
</td>
</tr>
}
</tbody>
</table>
</div>
</body>
</html>
推荐阅读
- reactjs - React-Redux 容器测试单元
- python - 有没有办法链接多个模型并在单个响应中查询它们?
- python - 使用 Ernie 进行文本分类 - 如何查看预测值
- windows-10 - 无法从网络共享运行 EXE
- java - 获取我的 .jar 文件旁边的文件夹的位置
- r - R write.csv2 输出显示空字符串
- tags - 如何根据标签列表过滤数据源 (AWS AMI)
- python - Numpy 数组 - 两个未知维度 - png 文件
- android - 在 Android Studio 中将图像保存到设备存储
- json - 渲染错误:“TypeError:无法读取未定义的属性''”