博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
前端:DataTable使用示例
阅读量:5827 次
发布时间:2019-06-18

本文共 5736 字,大约阅读时间需要 19 分钟。

function fixNumber(num, fix) {
var str = num.toString(); if (str.length < fix) {
var prefix = ""; for (var i = 0; i < fix - str.length; i++) {
prefix += "0"; } str = prefix + str; } return str;}var dataTable_language = {
"lengthMenu" : "显示 _MENU_ 条每页", "zeroRecords" : "没有找到任何信息!", "infoEmpty" : "无数据", "emptyTable" : "没有数据找到", "info" : "显示第 _START_ 到第 _END_ 条(共 _TOTAL_ 条)", "infoFiltered" : "(来自 _MAX_ 条的过滤数据)", "infoPostFix" : "", "thousands" : ",", "loadingRecords" : "载入中...", "processing" : "处理中...", "search" : "搜索:", "paginate" : {
"first" : "首页", "last" : "尾页", "next" : "下一页", "previous" : "上一页" }, "aria" : {
"sortAscending" : ": 升序排列", "sortDescending" : ": 降序排列" }};var dataTable_dom = "t<'t-page'p>";$("#table_comment").DataTable( {
"language" : dataTable_language, "dom" : dataTable_dom, "processing" : true, "ordering" : false, "searching" : false, "serverSide" : true, "autoWidth" : false, "pageLength" : 10, "ajax" : {
"url" : table_comment_url, "data" : function(d) {
d.id = instr_id }, "dataSrc" : "data" }, "columnDefs" : [ {
"width" : "500px", "targets" : [ 0 ], "data" : null, "render" : function(data, type, full) {
var comm_content = data.comm_content; var date = new Date(data.comm_time); var comm_time = fixNumber(date.getFullYear(), 2) + "-" + fixNumber((date.getMonth() + 1), 2) + "-" + fixNumber(date.getDate(), 2) + " " + fixNumber(date.getHours(), 2) + ":" + fixNumber(date.getMinutes(), 2); var text = ""; text += '
' + comm_content + '
'; text += '
' + comm_time + '
'; return text; } }, {
"targets" : [ 1 ], "data" : null, "render" : function(data, type, full) {
var comm_value = data.comm_value; var text = '
'; for (var i = 0; i < 5; i++) {
if (i < comm_value) {
text += '
'; } else {
text += '
'; } } text += '
'; return text; } }, {
"targets" : [ 2 ], "data" : null, "render" : function(data, type, full) {
var text = data.item_title; return text; } }, {
"targets" : [ 3 ], "data" : null, "render" : function(data, type, full) {
var nick_name = data.nick_name; nick_name = nick_name.substr(0, 1) + '***' + nick_name.substr(-1, 1); var user_place = data.province + " " + data.city; var text = '
' + nick_name + '
'; text += '
' + user_place + '
'; return text; } }]});$("#table_transaction").DataTable( {
"language" : dataTable_language, "dom" : dataTable_dom, "processing" : true, "ordering" : false, "searching" : false, "serverSide" : true, "autoWidth" : false, "pageLength" : 10, "ajax" : {
"url" : table_transaction_url, "data" : function(d) {
d.id = instr_id }, "dataSrc" : "data" }, "columnDefs" : [ {
"targets" : [ 0 ], "data" : null, "render" : function(data, type, full) {
var nick_name = data.nick_name; nick_name = nick_name.substr(0, 1) + '***' + nick_name.substr(-1, 1); var text = ""; text += '
'; return text; } }, {
"targets" : [ 1 ], "data" : null, "render" : function(data, type, full) {
var item_title = data.item_title; var descri = data.descri; var text = ""; text += '
' + item_title + '
'; text += '
' + descri + '
'; return text; } }, {
"targets" : [ 2 ], "data" : null, "render" : function(data, type, full) {
var text = data.qty; return text; } }, {
"targets" : [ 3 ], "data" : null, "render" : function(data, type, full) {
var date = new Date(data.comp_time); var dateT = fixNumber(date.getFullYear(), 2) + "-" + fixNumber((date.getMonth() + 1), 2) + "-" + fixNumber(date.getDate(), 2) + "
" + fixNumber(date.getHours(), 2) + ":" + fixNumber(date.getMinutes(), 2) + ":" + fixNumber(date.getSeconds(), 2); var text = ""; text += '
' + dateT + '
'; return text; } } ]});

转载于:https://www.cnblogs.com/xuejianbest/p/10284952.html

你可能感兴趣的文章
JavaScript学习笔记(十三)——生成器(generator)
查看>>
hibernate保存失败
查看>>
MySQL增量订阅&消费组件Canal POC
查看>>
Sqlite多线程
查看>>
数据结构-时间复杂度
查看>>
对象与字符串相互转换
查看>>
[NOIp2017提高组]小凯的疑惑
查看>>
《C程序设计语言》练习1-5
查看>>
$\frac{dy}{dx}$ 是什么意思?
查看>>
Go开发之路(目录)
查看>>
RHEL6.5安装成功ORACLE11GR2之后,编写PROC程序出错解决方法
查看>>
(50)与magento集成
查看>>
Ubuntu设置python3为默认版本
查看>>
JsonCpp 的使用
查看>>
问题账户需求分析
查看>>
JavaSE-代码块
查看>>
爬取所有校园新闻
查看>>
32、SpringBoot-整合Dubbo
查看>>
python面向对象基础
查看>>
HDU 2044 一只小蜜蜂(递归)
查看>>