使用jquery datatable和bootsrap創(chuàng)建表格實(shí)例代碼
使用jquery-datatable插件
bootstrap前端框架
json
一.創(chuàng)建demo.html
代碼塊
代碼塊語(yǔ)法遵循標(biāo)準(zhǔn)markdown代碼,例如:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html lang="en" class="app">
<head>
<meta charset="utf-8" />
<title>XXX服務(wù)平臺(tái)</title>
<meta name="description"
content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1" />
<link rel="stylesheet"
href="<%=request.getContextPath()%>/www/AL_app/js/jPlayer/jplayer.flat.css" rel="external nofollow"
type="text/css" />
<link rel="stylesheet"
href="<%=request.getContextPath()%>/www/AL_app/css/bootstrap.css" rel="external nofollow"
type="text/css" />
<link rel="stylesheet"
href="<%=request.getContextPath()%>/www/AL_app/css/font.css" rel="external nofollow"
type="text/css" />
<link rel="stylesheet"
href="<%=request.getContextPath()%>/www/AL_app/css/app.css" rel="external nofollow"
type="text/css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/www/AL_app/js/datatables/datatables.css" rel="external nofollow" type="text/css"/>
<!--[if lt IE 9]>
<script src="js/ie/html5shiv.js"></script>
<script src="js/ie/respond.min.js"></script>
<script src="js/ie/excanvas.js"></script>
<![endif]-->
</head>
<body class=""
<!-- ***********醫(yī)用藥典開始************** -->
<section id="content">
<section class="vbox">
<section class="scrollable padder">
<div class="m-b-md">
<h3 class="m-b-none"></h3>
</div>
<div class="m-b-md">
<h3 class="m-b-none">中醫(yī)藥典</h3>
</div>
<section class="panel panel-default">
<header class="panel-heading">
清單
<i class="fa fa-info-sign text-muted" data-toggle="tooltip" data-placement="bottom" data-title="ajax to load the data."></i>
</header>
<div class="table-responsive">
<table class="table table-striped m-b-none" data-ride="datatables">
<thead>
<tr>
<th style="width:15%" >序號(hào)</th>
<th style="width:20%">藥名</th>
<th style="width:20%">拼音簡(jiǎn)稱</th>
<th style="width:15%">用法</th>
<th style="width:15%">操作</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</section>
</section>
</section>
<a href="#" rel="external nofollow" class="hide nav-off-screen-block" data-toggle="class:nav-off-screen,open" data-target="#nav,html"></a>
</section>
<!-- ***********醫(yī)用藥典結(jié)束************** -->
</section>
</section>
</section>
<script src="<%=request.getContextPath()%>/www/AL_app/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="<%=request.getContextPath()%>/www/AL_app/js/bootstrap.js"></script>
<!-- App -->
<script src="<%=request.getContextPath()%>/www/AL_app/js/app.js"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/www/AL_app/js/jPlayer/demo.js"></script>
<script src="<%=request.getContextPath()%>/www/AL_app/jh_js/jq.dataTable.js"></script>
<script src="<%=request.getContextPath()%>/www/AL_app/js/datatables/jquery.csv-0.71.min.js"></script>
<script src="<%=request.getContextPath()%>/www/AL_app/drugs/demo.js"></script>
<script src="<%=request.getContextPath()%>/www/AL_app/js/app.plugin.js"></script>
</body>
</html>
二.創(chuàng)建一個(gè)drugs.json
{
"aaData": [
{
"序號(hào)": "1",
"藥名": "白術(shù)",
"拼音簡(jiǎn)稱": "bzh",
"用法": "內(nèi)服",
"操作": "編輯"
},
{
"序號(hào)": "3",
"藥名": "白術(shù)",
"拼音簡(jiǎn)稱": "bzh",
"用法": "內(nèi)服",
"操作": "編輯"
},
{
"序號(hào)": "4",
"藥名": "白術(shù)",
"拼音簡(jiǎn)稱": "bzh",
"用法": "內(nèi)服",
"操作": "編輯"
},
{
"序號(hào)": "5",
"藥名": "白術(shù)",
"拼音簡(jiǎn)稱": "bzh",
"用法": "內(nèi)服",
"操作": "編輯"
},
{
"序號(hào)": "6",
"藥名": "白術(shù)",
"拼音簡(jiǎn)稱": "bzh",
"用法": "內(nèi)服",
"操作": "編輯"
}
]
三.創(chuàng)建一個(gè)demo.js
/** 使用jquery-datatable異步請(qǐng)求數(shù)據(jù)創(chuàng)建表格 **/
+function ($) { "use strict";
$(function(){
// datatable
$('[data-ride="datatables"]').each(function() {
var oTable = $(this).dataTable( {
"bProcessing": true,
"sAjaxSource": "www/AL_app/drugs/drugs.json",//異步請(qǐng)求json數(shù)據(jù)
"sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col-sm-6'p>>",
"sPaginationType": "full",
//給表格單元的頭信息命名
"aoColumns": [
{ "mData": "序號(hào)" },
{ "mData": "藥名" },
{ "mData": "拼音簡(jiǎn)稱" },
{ "mData": "用法" },
{ "mData": "操作" }
]
} );
});
}(window.jQuery);
四.截圖如下所示

以上所述是小編給大家介紹的使用jquery datatable和bootsrap創(chuàng)建表格實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
jQuery文字橫向滾動(dòng)效果的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇jQuery文字橫向滾動(dòng)效果的實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05
jQuery使用append在html元素后同時(shí)添加多項(xiàng)內(nèi)容的方法
這篇文章主要介紹了jQuery使用append在html元素后同時(shí)添加多項(xiàng)內(nèi)容的方法,實(shí)例分析了jQuery中append追加內(nèi)容的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
JQuery 國(guó)際象棋棋盤 實(shí)現(xiàn)代碼
前些時(shí)候?yàn)榱耸煜?guó)際象棋的各種開局,隨手寫了一個(gè)很簡(jiǎn)單的國(guó)際象棋棋盤(實(shí)在找不到現(xiàn)成的)。2009-06-06
jQuery判斷div隨滾動(dòng)條滾動(dòng)到一定位置后停止
這篇文章主要介紹了jQuery判斷div隨滾動(dòng)條滾動(dòng)到一定位置后停止的方法,需要的朋友可以參考下2014-04-04
jQuery+css last-child實(shí)現(xiàn)選擇最后一個(gè)子元素操作示例
這篇文章主要介紹了jQuery+css last-child實(shí)現(xiàn)選擇最后一個(gè)子元素操作,結(jié)合實(shí)例形式分析了jQuery結(jié)合css進(jìn)行頁(yè)面元素選擇與樣式修改相關(guān)操作技巧,需要的朋友可以參考下2018-12-12
Jquery原生態(tài)實(shí)現(xiàn)表格header頭隨滾動(dòng)條滾動(dòng)而滾動(dòng)
表頭是浮動(dòng)的,因?yàn)閮?nèi)容在同一頁(yè)面展示,當(dāng)滾動(dòng)時(shí),看不到列頭,為了改動(dòng)少只能使用jquery原生態(tài)實(shí)現(xiàn)滾動(dòng)2014-03-03
為jQuery-easyui的tab組件添加右鍵菜單功能的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇為jQuery-easyui的tab組件添加右鍵菜單功能的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
jQuery實(shí)現(xiàn)倒計(jì)時(shí)重新發(fā)送短信驗(yàn)證碼功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)倒計(jì)時(shí)重新發(fā)送短信驗(yàn)證碼功能,結(jié)合實(shí)例形式分析了基于jQuery的倒計(jì)時(shí)操作功能實(shí)現(xiàn)方法,涉及jQuery表單提交、驗(yàn)證、正則操作等技巧,需要的朋友可以參考下2017-01-01

