基本创建

<!--定义操作列按钮模板-->
<script id="tpl" type="text/x-handlebars-template">
{{#each func}}
<button type="button" class="btn btn-{{this.type}} btn-sm" onclick="{{this.fn}}">{{this.name}}</button>
{{/each}}
</script> <div class="row">
<div class="col-lg-12">
<h1 class="page-header">菜单管理</h1>
</div>
</div>
<!-- /.col-lg-12 -->
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
DataTable
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="dataTable_wrapper">
<table id="dataTables-example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Menu_ID</th>
<th>Menu_Code</th>
<th>Menu_ParentCode</th>
<th>Menu_Order</th>
<th>Menu_Name</th>
<th>Menu_Url</th>
<th>Menu_Icon</th>
<th>Menu_Enable</th>
<th>操作</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div> <!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">新增</h4>
</div>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" id="name" placeholder="姓名">
</div>
<div class="form-group">
<input type="text" class="form-control" id="position" placeholder="位置">
</div>
<div class="form-group">
<input type="text" class="form-control" id="salary" placeholder="薪资">
</div>
<div class="form-group">
<input type="text" class="form-control" id="start_date" placeholder="时间"
data-date-format="yyyy/mm/dd">
</div>
<div class="form-group">
<input type="text" class="form-control" id="office" placeholder="工作地点">
</div>
<div class="form-group">
<input type="text" class="form-control" id="extn" placeholder="编号">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info" id="initData">添加模拟数据</button>
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="save">保存</button>
</div>
</div>
</div>
</div> <script>
$("div.toolbar").html('<b style="color:red">自定义文字、图片等等</b>'); //创建datatables
$('#dataTables-example').DataTable({
//"autoWidth": true,//自适应宽度
"jQueryUI": true,
responsive: true,
"processing": true,
"bSort": false, //是否支持排序功能
"oLanguage": {
"sLengthMenu": "每页显示 _MENU_ 条记录",
"sZeroRecords": "对不起,查询不到任何相关数据",
"sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
"sInfoEmtpy": "找不到相关数据",
"sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
"sProcessing": "正在加载中...",
"sSearch": "搜索",
"sUrl": "", //多语言配置文件,可将oLanguage的设置放在一个txt文件中,例:Javascript/datatable/dtCH.txt
"oPaginate": {
"sFirst": "第一页",
"sPrevious": " 上一页 ",
"sNext": " 下一页 ",
"sLast": " 最后一页 "
}
}, //多语言配置
//"ajax": '/Menu/LoadMenuList',
"ajax": {
"type": "post",
"url": '/Menu/LoadMenuList',
},
columns: [
{ data: 'Menu_ID' },
{ data: 'Menu_Code' },
{ data: 'Menu_ParentCode' },
{ data: 'Menu_Order' },
{ data: 'Menu_Name' },
{ data: 'Menu_Url' },
{ data: 'Menu_Icon' },
{ data: 'Menu_Enable' },
{ data: null },
],
//设置定义列的初始属性
"columnDefs": [{
"targets": -1,//编辑
"data": null,
"defaultContent": "<button id='editrow' class='btn btn-primary' type='button'><i class='fa fa-edit'></i></button> " +
"<button id='delrow' class='btn btn-primary' type='button'><i class='fa fa-trash-o'></i></button>"
}, ],
//定义datables布局
"dom": "<'row'<'col-xs-2'l><'#mytool.col-xs-4'><'col-xs-6'f>r>" +
"t" +
"<'row'<'col-xs-6'i><'col-xs-6'p>>",
//初始化结束后的回调函数
initComplete: function () {
$("#mytool").append('<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#myModal">添加</button>');
$("#datainit").on("click", initData);
}
}); // 数据删除
$('#dataTables-example tbody').on('click', 'button#delrow', function () {
var data = tables.row($(this).parents('tr')).data();
$.ajax({
url: 'deltable',
type: 'POST',
dataType: 'json',
data: { id: data[0] },
})
.done(function (data) {
if (data == "success") {
tables.ajax.reload();
};
})
.fail(function () {
alert("error");
});
}); // 数据编辑
$('#dataTables-example tbody').on('click', 'button#editrow', function () {
//var data = tables.row($(this).parents('tr')).data();
//var fields = $("#add-form").serializeArray();
//jQuery.each(fields, function (i, field) {
// //jquery根据name属性查找
// $(":input[name='" + field.name + "']").val(data[i]);
//});
//$(":input[name='mark']").val("edit");
$("#myModal").modal("show");//弹出框show });
</script>

Jquery.Datatables 基本创建方法的更多相关文章

  1. Jquery datatables 重载数据方法

    参考这里 { RefreshTable('#table-example', '/BlogManage/GetLabelData'); } function RefreshTable(tableId, ...

  2. jQuery的无new创建方法

    一般我们去写一个框架,会采用什么样的设计呢?比如设计一个jQuery框架,一般我们会创建一个函数对象 function jQuery(params){ //构造函数 }jQuery.prototype ...

  3. jQuery中动态创建、添加元素的方法总结

    <input type="button" value="创建元素" id="btn"> <div id="box ...

  4. jquery datatables api (转)

    学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...

  5. 最全的jquery datatables api 使用详解

    学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/20069 ...

  6. jquery datatables api

    原文地址 学习可参考:http://www.guoxk.com/node/jquery-datatables http://yuemeiqing2008-163-com.iteye.com/blog/ ...

  7. [jQuery]jQuery DataTables插件自定义Ajax分页实现

    前言 昨天在博客园的博问上帮一位园友解决了一个问题,我觉得有必要记录一下,万一有人也遇上了呢. 问题描述 园友是做前端的,产品经理要求他使用jQuery DataTables插件显示一个列表,要实现分 ...

  8. jquery常用函数与方法

    1.delay(duration,[queueName]) 设置一个延时来推迟执行队列中之后的项目.jQuery 1.4新增.用于将队列中的函数延时执行.他既可以推迟动画队列的执行,也可以用于自定义队 ...

  9. jQuery Mobile 中创建按钮

    在 jQuery Mobile 中创建按钮 jQuery Mobile 中的按钮可通过三种方法创建: 使用 <button> 元素 使用 <input> 元素 使用 data- ...

随机推荐

  1. web安全及防护

    本文将对web方面的安全问题以及相应的防护方法进行一个简单的介绍. SQL注入(SQL Injection) 原理:就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺 ...

  2. 跟着百度学PHP[4]OOP面对对象编程-15-魔术方法__call方法

    简而言之就是调用了一个类中没有的方法就会自动调用__call()方法, 该参数有两个必须的参数! 第一个参数:调用的不存在的方法的方法名. 第二个参数:调用不存在的方法的参数. 但是总的说回来,__c ...

  3. huffman编码压缩算法(转)

    参考:http://blog.csdn.net/sunmenggmail/article/details/7598012 笔试时遇到的一道题.

  4. svn下目录说明

    Branch 目录 : 该SVN 的Branch目录下存放的是:跟工程项目相关的各个工程版本分支.该目录下面的版本分支可能会被修改合并.不是稳定的版本. Document 目录:该SVN 的Docum ...

  5. django的ajax对应前端的瀑布流方法

    html {% load xx %} <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  6. 网页的title左边的小图片怎么添加

    首先,代码中的title标签里是不能加图片的.但是浏览器标提栏前面是可以加一个小图标的. 解决方案:第一步,做一个16 X 16像素的ico格式的图标.具体操作方法是,先在Photoshop中做一个透 ...

  7. linux学习之一些琐碎知识点

    一.python 问:django中project和app之间到底有什么不同? 答:他们的区别就是一个是配置,另一个是代码. 一个project包含很多个django app以及对它们的配置.技术上, ...

  8. php bom \ufeff

    2015年5月29日 16:50:56 星期五 五月的最后一个周五............. 前两天遇到一个问题 PHP 返回json数据, 其他人死活解析不出来 json_last_error(); ...

  9. Java for LeetCode 205 Isomorphic Strings

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  10. a byte of python (摘01)

    a byte of python 第一章 介绍 Python 特色 简单.易学.免费.开源 高层语言.可移植性.解释性 面向对象.可扩展性.可嵌入性 丰富的库 第二章 安装Python http:// ...