博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tornado+datatables分页
阅读量:6429 次
发布时间:2019-06-23

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

  hot3.png

js代码

$(document).ready(function() {    $('.table-sort').DataTable( {        //"aaSorting": [[ 4, "desc" ]],//默认第几个排序        "processing": true,        "serverSide": true,        "bAutoWidth": true,   //自动宽度        "iDisplayLength": 10,  //显示条数        "bFilter": true,   //是否启用过滤        "bPaginate": true,    //翻页功能        "bLengthChange": true,   //改变每页显示数量        "bSort": false,    //排序功能        "bStateSave": false,//状态保存        "sPaginationType": "full_numbers",        "ajax" : "/returnmessage",        /*        "ajax": {            "url" : "/returnmessage",            "type" : "POST",        },        */        /* 一直提示DataTables warning : Requested unknown parameter '10' from the data source for row 0 错误,按照网上的添加下面aocolumndefs 就正常了,原因不明 */        "aoColumnDefs": [{            "sDefaultContent": '',            "aTargets": [ '_all' ]                        }],        "columnDefs": [{            "orderable": false,//禁用排序            "targets": [0,1,2,3,5,6,7,8,9,10]   //指定的列            }],    } );} );

tornado代码,用的torndb

db = torndb.Connection("127.0.0.1:3306","dbname","user","password")class ReturnmessageHandler(tornado.web.RequestHandler):    def get(self):        pagesize =  str(self.get_argument("length")).strip()        start =  str(self.get_argument("start")).strip()        search =  str(self.get_argument("search[value]")).strip()        message =[]        try:            if search:                sql = "SELECT * FROM maillog where mailsubject like '{0}' limit {1} offset {2}".format("%%"+search+"%%",pagesize,start)                msgnumsql = "select count(*) from maillog where mailsubject like '%s'" %("%%"+search+"%%")            else:                sql = 'SELECT * FROM maillog limit %s offset %s' % (pagesize,start)                msgnumsql = 'select count(*) from maillog'            print msgnumsql            messagedata = db.query(sql)            message_num= db.query(msgnumsql)[0]['count(*)']            print message_num            for y in messagedata:                checkl = '' % y.queueid                options = '' %y.queueid                arr = [checkl,y.queueid,y.sender,y.receive,y.mailtime,y.mailsubject,y.mailsize,y.mailstatus,y.reason,y.codechar,options]                message.append(arr)            messagedata= {                "recordsTotal": message_num,                "recordsFiltered": message_num,                "data": message                }            self.write(json.dumps(messagedata))        except Exception as e:            print ("error %s" %format(e))        finally:            pass

tornado代码,用的mysql.connector

class ReturnmessageHandler(tornado.web.RequestHandler):    def get(self):        pagesize =  str(self.get_argument("length")).strip()        start =  str(self.get_argument("start")).strip()        search =  str(self.get_argument("search[value]")).strip()        message =[]        conn = mysql.connector.connect(**dbconfig)        cursor = conn.cursor()        try:            msgnumsql = 'select count(*) from maillog'            cursor.execute(msgnumsql)            message_num = cursor.fetchall()[0][0]            if search:                sql = 'SELECT * FROM maillog where mailsubject lise "%%%s%%" limit %s offset %s' % (search,pagesize,start)            else:                sql = 'SELECT * FROM maillog limit %s offset %s' % (pagesize,start)            cursor.execute(sql)            messagedata = cursor.fetchall()            for x,y in enumerate(messagedata):                message.append(list(y))            messagedata= {                "recordsTotal": message_num,                "recordsFiltered": message_num,                "data": message                }            self.write(json.dumps(messagedata))         except Exception as e:            print ("%s mysql error! " +format(e))        finally:            cursor.close()            conn.close()

转载于:https://my.oschina.net/hxily/blog/506319

你可能感兴趣的文章
手机共享电脑网络
查看>>
ORM框架Hibernate (四) 一对一单向、双向关联映射
查看>>
20140616 科技脉搏 -最大颠覆来自创业公司与边缘产业
查看>>
offsetLeft, offsetTop以及postion().left , postion().top有神马区别
查看>>
visual studio 中GIT的用法
查看>>
数据库中触发器before与after认识
查看>>
手动露天广场和立方体
查看>>
随机选择
查看>>
【Java并发编程三】闭锁
查看>>
分布式事务中遇到的 “与基础事务管理器的通信失败”的解决方法
查看>>
让你的Git水平更上一层楼的10个小贴士
查看>>
c++ string 之 find_first_not_of 源码
查看>>
mybatis中的#和$的区别
查看>>
ubuntu下搭建NDK环境
查看>>
MessageDigest简单介绍
查看>>
webpack window 使用sass来编译css样式
查看>>
D3 & Data Visualization in Ext JS
查看>>
java通过UUID生成16位唯一订单号
查看>>
001-web基本程序搭建
查看>>
函数指针和指针函数
查看>>