jQuery Table 排序器 - 无法让 table 对 table 的列进行排序(单元格值可以在排序前由 jQuery 动态更改)
jQuery Table Sorter - Unable to get table to sort on a column of a table (cell values can be changed dynamically by jQuery before sort)
我有 table 行,最后一个单元格是或否。该列不响应排序并且可以在更改排序顺序之前进行修改,但是没有排序。
我无法生成最小的完整可验证示例,但我可以说初始化代码非常简单。
$(".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
Controller/ViewModels
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>
我有 table 行,最后一个单元格是或否。该列不响应排序并且可以在更改排序顺序之前进行修改,但是没有排序。
我无法生成最小的完整可验证示例,但我可以说初始化代码非常简单。
$(".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
Controller/ViewModels
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>