<code>
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello world!</title>
<link href="lib/css/zui.min.css" rel="stylesheet">
<link href="lib/datatable/zui.datatable.min.css" rel="stylesheet">
<script src="lib/jquery/jquery.js"></script>
<script src="lib/js/zui.min.js"></script>
<script src="lib/datatable/zui.datatable.min.js"></script>
</head>
<body>
<table id="tab" class="datatable" data-checkable="true" data-sortable="true"></table>
<button class="btn btn-primary" type="button" id="btn_click">
主要1按钮
</button>
<button class="btn btn-primary" type="button" id="btn_click2">
主要2按钮
</button>
<script>
$('#btn_click').click(function () {
/* 使用选项选项来初始化数据 */
$('table.datatable').datatable({
data: {
cols: [
{width: 80, text: '#', type: 'number', flex: false, colClass: 'text-center'},
{width: 160, text: '时间', type: 'date', flex: false, sort: 'down'},
{width: 80, text: '名称', type: 'string', flex: true, colClass: ''}
],
rows: [
{checked: false, data: [1, '2016-01-18 11:05:15', '名称示例1']},
{checked: false, data: [2, '2016-01-20 12:06:16', '名称示例2']},
// 更多数据
]
}
});
})
$('#btn_click2').click(function () {
// 使用data参数更新数据:
$('table.datatable').datatable('load', {
cols: [
{width: 80, text: '新的#', type: 'number', flex: false, colClass: 'text-center'},
{width: 160, text: '新的时间', type: 'date', flex: false, sort: 'down'},
{width: 80, text: '新的名称', type: 'string', flex: true, colClass: ''}
],
rows: [
{checked: false, data: [1, '2016-01-18 11:09:36', '新的名称示例1']},
{checked: false, data: [2, '2016-01-22 12:06:16', '新的名称示例2']},
// 更多数据
]
});
})
</script>
</body>
</html>
</code>
网友评论