欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-15 16:11:04
 使用jquery-datatable插件 bootstrap前端框架 json 一.创建demo.html 代码块 代码块语法遵循标准ma...

 使用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 + "/";
%>
<!doctype html>
<html lang="en" class="app">
<head>
<meta charset="utf-8" />
<title>xxx服务平台</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=""
<!-- ***********医用药典开始************** -->
<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">中医药典</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%" >序号</th>
            <th style="width:20%">药名</th>
            <th style="width:20%">拼音简称</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>
    <!-- ***********医用药典结束************** -->
      </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>

二.创建一个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);

四.截图如下所示

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

以上所述是小编给大家介绍的使用jquery datatable和bootsrap创建表格实例代码,希望对大家有所帮助