dataTables 서버측 페이지 나누기 서버사이드(for django)
4839 단어 django
ip_address
host_name
lease_expiry_time
lease_duration
time_span
js
$(document).ready(function () {
$("#tb").DataTable({
"paging": true,
"searching": true,
"processing": true,
"serverSide": true,
// "destroy": true,
// "pageLength": 10,
"ordering": false,
// "renderer": "bootstrap",// :Bootstrap jquery-ui
// "pagingType": "simple_numbers",// :simple,simple_numbers,full,full_numbers
// "autoWidth": true,
// "stateSave": true,// , comTable.fnDraw(false);
"ajax": {
"url": "/example/paging/paging/",
"type": "post"
},
// "columns": [ // data ,
// { "data": "id" },
// { "data": "name" },
// { "data": "dept" },
// { "data": "phone" }
// ]
"columnDefs": [ //
{
"render": function (data, type, row) { //data: row:
if (data == "10.199.50.125") {
return "" + data + "";
} else {
return data;
}
},
"targets": 0 //
},
{
"render": function (data, type, row) {
if (row[0] == "10.199.50.139") { // IP
return "" + data + "";
} else {
return data;
}
},
"targets": 1 //
}
]
});
});
urls.py
# : url url
url(r'^example/paging/$', paging.index),
url(r'^example/paging/paging/$', paging.paging),
views.py
def index(request):
return render(request, 'example/paging/body01.html')
#
def paging(request):
draw = int(request.POST.get('draw')) #
start = int(request.POST.get('start')) #
length = int(request.POST.get('length')) #
search_key = request.POST.get('search[value]') #
order_column = request.POST.get('order[0][column]') #
order_column = request.POST.get('order[0][dir]') # :ase/desc
# sql , ,
# if search_key:
# result = query(search_key)
# else:
# result = select_all()
# data = result[start:start+length]
# count = len(result)
# sql ,
if search_key:
result, count = query(search_key)
data = result[start:start + length]
else:
data = select_by_page(start, start + length)
count = all_count()
dic = {
'draw': draw,
'recordsTotal': count,
'recordsFiltered': count,
'data': data,
}
return HttpResponse(json.dumps(dic), content_type='application/json')
# all
def select_all():
cursor = connection.cursor()
# Object of type 'datetime' is not JSON serializable , to_char
# ORA-00911: invalid character ,
sql = "select ip_address,host_name,to_char(lease_expiry_time),to_char(lease_duration),to_char(time_span) from example_paging order by ip_address"
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()
return result
# sql
def select_by_page(start, end):
cursor = connection.cursor()
# Object of type 'datetime' is not JSON serializable , to_char
# ORA-00911: invalid character ,
# oracle , rownum 1 , rownum,
sql = """
select * from
(select ip_address,host_name,to_char(lease_expiry_time),to_char(lease_duration),to_char(time_span),rownum as rn
from example_paging order by ip_address )
where rn>=%s and rn
참조 자료:
https://www.datatables.net/examples/server_side/post.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Django의 질문 및 답변 웹사이트환영 친구, 이것은 우리의 새로운 블로그입니다. 이 블로그에서는 , 과 같은 Question-n-Answer 웹사이트를 만들고 있습니다. 이 웹사이트는 회원가입 및 로그인이 가능합니다. 로그인 후 사용자는 사용자의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.