gpt4 book ai didi

javascript - 无法使用DataTable的排序功能

转载 作者:行者123 更新时间:2023-11-28 18:19:51 25 4
gpt4 key购买 nike

我目前正在尝试学习和使用 ASP.NET 中的 DataTable。但是,我无法完成排序功能。我编写了代码,我已经显示了图标,但我无法单击它或触发任何事件。我是否错过了一些 javascript 或者我应该自己完成该功能?

我引用的是这个网站https://datatables.net/examples/basic_init/table_sorting.html

这是我尝试过的代码

母版页(仅限脚本)

  <link href="Content/bootstrap.min.css" rel="stylesheet" />

<!-- Custom CSS -->
<link href="Content/sb-admin.css" rel="stylesheet" />
<link href="Content/customCSS.css" rel="stylesheet" />
<link href="Content/DataTables-1.10.12/media/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<link href="Content/DataTables-1.10.12/media/css/jquery.dataTables.min.css" rel="stylesheet" />

<!-- Morris Charts CSS -->
<link href="Content/plugins/morris.css" rel="stylesheet" />

<!-- Custom Fonts -->
<link href="fonts/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

<!-- Bootstrap Core JavaScript -->
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.12.3.js"></script>
<script src="Content/DataTables-1.10.12/media/js/jquery.dataTables.min.js"></script>
<script src="Content/DataTables-1.10.12/media/js/dataTables.bootstrap.min.js"></script>

<!-- Morris Charts JavaScript -->
<script src="Scripts/plugins/morris/raphael.min.js"></script>
<script src="Scripts/plugins/morris/morris.min.js"></script>
<script src="Scripts/plugins/morris/morris-data.js"></script>

ASPX

<script>
function onPageLoad() {
$(document).on("dblclick", "#tableCourseStructure tbody tr", function () {
var $this = $(this);
var row = $this.closest("tr");
row.find('td:eq(1)');
var courseCode = row.find('td:first').text();
window.location.href = "UpdateCourse.aspx?CourseCode=" + courseCode;
});
}
</script>

<table id="tableCourseStructure" class="table table-striped table-bordered dataTable no-footer hover display" role="grid">
<thead>
<tr role="row">
<th>Course Code</th>
<th>Course Version</th>
<th>Course Title</th>
<th>Last Modified Date</th>
</tr>
</thead>
<tbody>
<%=getCourseData()%>
</tbody>
</table>

ASPX.CS

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
retrieveBAL retrieveBAL = new retrieveBAL();
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "onPageLoad();", true);
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "sortingTable();", true);
}

}

protected void ddlCourseCategory_SelectedIndexChanged(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "onPageLoad();", true);
}

public string getCourseData()
{
string data = "";
retrieveBAL retrieveBAL = new retrieveBAL();

foreach (DataRow row in retrieveBAL.retrieveCourseInfoByCategory(ddlCourseCategory.SelectedValue).Tables[0].Rows)
{
data += "<tr><td>" + row["courseCode"].ToString() + "</td><td>" + row["courseVersion"].ToString() + "</td><td>" + row["courseTitle"].ToString() + "</td><td>" + row["LastModifiedDate"].ToString() + "</td></tr>";
}

return data;

}

最佳答案

您似乎缺少实际的 DataTable() 函数调用,该函数会将您的 html 表 转换为 DataTable:

$('#tableCourseStructure').DataTable();

您的 CSS 可能使其看起来像 DataTable,但如果没有上述内容,您将无法获得任何功能。

关于javascript - 无法使用DataTable的排序功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40086884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com