使用jquery datatable和bootsrap创建表格实例代码

 使用jquery-datatable插件

bootstrap前端框架

json

一.创建demo.html

代码块

代码块语法遵循标准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 + "https://www.jb51.net/"; %> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>XXX服务平台</title> <meta content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" /> <meta content="width=device-width, initial-scale=1, maximum-scale=1" /> <link href="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/jPlayer/jplayer.flat.css" type="text/css" /> <link href="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/css/bootstrap.css" type="text/css" /> <link href="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/css/font.css" type="text/css" /> <link href="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/css/app.css" type="text/css" /> <link href="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/datatables/datatables.css" type="text/css"/> <!--[if lt IE 9]> <script src="https://www.jb51.net/js/ie/html5shiv.js"></script> <script src="https://www.jb51.net/js/ie/respond.min.js"></script> <script src="https://www.jb51.net/js/ie/excanvas.js"></script> <![endif]--> </head> <body <!-- ***********医用药典开始************** --> <section> <section> <section> <div> <h3></h3> </div> <div> <h3>中医药典</h3> </div> <section> <header> 清单 <i data-toggle="tooltip" data-placement="bottom" data-title="ajax to load the data."></i> </header> <div> <table data-ride="datatables"> <thead> <tr> <th >序号</th> <th>药名</th> <th>拼音简称</th> <th>用法</th> <th>操作</th> </tr> </thead> <tbody> </tbody> </table> </div> </section> </section> </section> <a href="#" data-toggle="class:nav-off-screen,open" data-target="#nav,html"></a> </section> <!-- ***********医用药典结束************** --> </section> </section> </section> <script src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/jquery.min.js"></script> <!-- Bootstrap --> <script src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/bootstrap.js"></script> <!-- App --> <script src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/app.js"></script> <script type="text/javascript" src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/jPlayer/demo.js"></script> <script src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/jh_js/jq.dataTable.js"></script> <script src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/datatables/jquery.csv-0.71.min.js"></script> <script src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/drugs/demo.js"></script> <script src="https://www.jb51.net/<%=request.getContextPath()%>/www/AL_app/js/app.plugin.js"></script> </body> </html>

二.创建一个drugs.json

{ "aaData": [ { "序号": "1", "药名": "白术", "拼音简称": "bzh", "用法": "内服", "操作": "编辑" }, { "序号": "3", "药名": "白术", "拼音简称": "bzh", "用法": "内服", "操作": "编辑" }, { "序号": "4", "药名": "白术", "拼音简称": "bzh", "用法": "内服", "操作": "编辑" }, { "序号": "5", "药名": "白术", "拼音简称": "bzh", "用法": "内服", "操作": "编辑" }, { "序号": "6", "药名": "白术", "拼音简称": "bzh", "用法": "内服", "操作": "编辑" } ]

三.创建一个demo.js

/** 使用jquery-datatable异步请求数据创建表格 **/ +function ($) { "use strict"; $(function(){ // datatable $('[data-ride="datatables"]').each(function() { var oTable = $(this).dataTable( { "bProcessing": true, "sAjaxSource": "www/AL_app/drugs/drugs.json",//异步请求json数据 "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": "序号" }, { "mData": "药名" }, { "mData": "拼音简称" }, { "mData": "用法" }, { "mData": "操作" } ] } ); }); }(window.jQuery);

四.截图如下所示

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwwzgp.html