DataTables中如何在最后一列添加按钮,添加的按钮点击后如何跳转到指定页面

L_不是你也不是他 L_不是你也不是他 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html charset=utf-8" >
<title>DataTables案例</title>

<!-- 本地路径 -->
<link rel="stylesheet" type="text/css" href="resources/css_t/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="resources/js_t/jquery.js"></script>
<script type="text/javascript" charset="utf8" src="resources/js_t/jquery.dataTables.js"></script>

<!-- 网络路径
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>
-->

</style>

</head>

<body>

<!-- 表格div -->
<div id="div_table">

<!-- 表格 -->
<table id="table_id" class="display">
<thead>
<tr>
<th>id</th>
<th>order_id</th>
<th>order_only</th>
<th>orderNum</th>
<th>client</th>
<th>client_orderNum</th>
<th>client_item_pro</th>
<th>product_code</th>
<th>product_name</th>
<th>amount</th>
<th>shipping_time</th>
<th>uncleared_num</th>
</tr>
</thead>

<tbody>
<tr>
<td>R1 D1</td>
<td>R1 D2</td>
<td>R1 D3</td>
<td>R1 D4</td>
<td>R1 D5</td>
<td>R1 D6</td>
<td>R1 D7</td>
<td>R1 D8</td>
<td>R1 D9</td>
<td>R1 D10</td>
<td>R1 D11</td>
<td>R1 D12</td>
</tr>

<tr>
<td>R2 D1</td>
<td>R2 D2</td>
<td>R2 D3</td>
<td>R2 D4</td>
<td>R2 D5</td>
<td>R2 D6</td>
<td>R2 D7</td>
<td>R2 D8</td>
<td>R2 D9</td>
<td>R2 D10</td>
<td>R2 D11</td>
<td>R2 D12</td>
</tr>
</tbody>
</table>

<!-- 按钮获取选中行 -->
<button id="buId_add">新增</button>
<button id="buId_update">修改(获取id)</button>
</div>

<!-- 显示时间div -->
<div id="div1id" style="width:200px;height:25px;border:2px solid green;position:absolute;top:10px;left:10ps;">
</div>

</body>

<!-- js代码 -->
<script type="text/javascript">

//获取实时时间
function getD1() {
//当前时间
var date = new Date();
//格式化
var d1 = date.toLocaleString();
//获取div
var div1 = document.getElementById("div1id");
div1.innerHTML = d1;
}
setInterval("getD1()",1000);

$(document).ready(function(){
var table=$('#table_id').DataTable({
paging:false, //表格分页
scrollY:400, //表格中使用滚动条
columns:[ //设定数据列
{data:"id"},
{data:"order_id"},
{data:"order_only"},
{data:"orderNum"},
{data:"client"},
{data:"client_orderNum"},
{data:"client_item_pro"},
{data:"product_code"},
{data:"product_name"},
{data:"amount"},
{data:"shipping_time"},
{data:"uncleared_num"},
]

});

//给行绑定选中事件
$('#table_id tbody').on('click','tr',function(){
if($(this).hasClass('selected')){
$(this).removeClass('selected');
}
else{
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
});

//给按钮绑定点击事件
$("#buId_update").click(function(){
var column1=table.row('.selected').data().id;
alert("点击修改按钮获取的id为:"+column1);
});

$("#buId_add").click(function(){
var column1=table.row('.selected').data().id;
alert("点击添加按钮获取的id为:"+column1);
});
});

</script>
</html>
...全文

相关推荐

jQuery中Datatables增加跳转到指定页功能

本文给大家分享jquery中datatable增加跳转到指定页面功能以及jquery datatable中加入双击跳转功能的实例代码,需要的朋友参考下

weixin_38697171

基于Datatables跳转到指定页的简单实例

下面小编就为大家带来一篇基于Datatables跳转到指定页的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38628183

JQuery.dataTables表格插件添加跳转到指定页

主要介绍了JQuery.dataTables表格插件添加跳转到指定页的解决方案,非常不错,具有参考借鉴价值,需要的朋友可以参考下

weixin_38500607

Buttons:Buttons是DataTables的扩展,它将控制按钮添加到表中

纽扣 DataTables的Buttons扩展提供了一组通用的选项,API方法和样式,以在将与DataTable交互的页面上显示按钮。 还提供了用于数据导出,打印和列可见性控制的模块。 安装 使用Buttons获得软件的主要方法是使用。 您还可以包括的各个文件。 有关完整的详细信息,请参见。 NPM和Bower 如果您更喜欢使用NPM或Bower之类的程序包管理器,则可以使用从该存储库构建的软件(名称为datatables.net-buttons获得分发存储库。 也可以通过在包名称后添加后缀来获得Bootstrap,Foundation和其他样式库的样式包。 请参阅DataTables 和安装页面以获取更多信息。 还包含有关如何将软件包管理器与DataTables一起使用的详细信息。 基本用法 使用DataTables构造函数中的buttons选项初始化buttons ,从而给出应显示

是十五呀

DataTables(二) —— 行分组信息展开与折叠的功能实现

DataTables行分组的展开与折叠功能的实现

花飘万家雪
评论 1
收藏 已收藏
分享
返回顶部
L_不是你也不是他
Web 开发 81,107 成员 341,720 内容