html代码
<table class="text-c table table-border table-bordered table-bg display table-sort radius table-striped table-hover">
<script type="text/javascript" src="{{ url_for('static',filename='lib/jquery/1.9.1/jquery.min.js') }}"></script>
<thead>
<tr class="text-c">
<th width="25"><input type="checkbox" name="all" value="all"></th>
<th>queue ID</th>
<th>发送人</th>
<th>接收人</th>
<th>发送时间</th>
<th>主题</th>
<th>邮件大小</th>
<th>发送状态</th>
<th>失败原因</th>
<th>邮件编码</th>
<th>操作</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
js代码
$(document).ready(function() {
$('.table-sort').DataTable( {
//"aaSorting": [[ 4, "desc" ]],//默认第几个排序
"processing": true,
"serverSide": true,
"bAutoWidth": true, //自动宽度
"iDisplayLength": 4, //显示条数
"bFilter": true, //是否启用过滤
"bPaginate": true, //翻页功能
"bLengthChange": true, //改变每页显示数量
"bSort": false, //排序功能
"bStateSave": false,//状态保存
"sPaginationType": "full_numbers",
"ajax" : "/testdata",
/*
"ajax": {
"url" : "/testdata",
"type" : "POST",
},
*/
"columnDefs": [{
"orderable": false,//禁用排序
"targets": [0,1,2,3,5,6,7,8,9,10] //指定的列
}]
} );
} );
server端flask代码
@app.route('/testdata',methods = ['GET', 'POST'])
def testdata():
pagesize = int(request.args.get('length'))
start = int(request.args.get('start'))
search = request.args.get('search[value]')
message =[]
if search:
message_list = Maillog.query.filter(or_(Maillog.mailsubject.like("%%%s%%" % search),Maillog.reason.like("%%%s%%" % search))).order_by(Maillog.mailtime.desc()).offset(start).limit(pagesize).all()
else:
message_list = Maillog.query.order_by(Maillog.mailtime.desc()).offset(start).limit(size).all()
message_num = len(Maillog.query.order_by(Maillog.mailtime.desc()).all())
for x,y in enumerate(message_list):
checkl = '<input name="checkid" type="checkbox" value="%s">' % y.queueid
options = '<a title="del" href="javascript:;" onclick=message_del("this","%s") class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a>' %y.queueid
messagey=[checkl,y.queueid,y.sender,y.receive,y.mailtime,y.mailsubject,y.mailsize,y.mailstatus,y.reason,y.codechar,options]
message.append(messagey)
messagedata= {
"recordsTotal": message_num,
"recordsFiltered": message_num,
"data": message
}
return json.dumps(messagedata)