您好,登錄后才能下訂單哦!
安裝
django-datatables-view
pip install django-datatables-view
前端配置-JS部分
$('#mytable').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"lengthMenu": [[20,50,100, -1], [20,50,100, "All"]],
"sPaginationType": "full_numbers",
"bProcessing": true, //開啟讀取服務器數據時顯示正在加載中……特別是大數據量的時候,開啟此功能比較好
"bServerSide": true, //開啟服務器模式
"sAjaxSource": "{% url 'proxy_list_json' %}", //給服務器發請求的url
});
django 后臺響應部分
from django_datatables_view.base_datatable_view import BaseDatatableView
def proxyAdmin(req):
#rows=Proxy.objects.all()[:100]
return render_to_response('data/proxyadmin.html')
class ProxyListJson(BaseDatatableView):
# The model we're going to show
model = Proxy #要分頁的類
# define the columns that will be returned
columns = ['ip', 'description', 'score', 'logdate'] #需要顯示的字段
# define column names that will be used in sorting
# order is important and should be same as order of columns
# displayed by datatables. For non sortable columns use empty
# value like ''
order_columns = ['ip','description', 'score', 'logdate'] #排序
# set max limit of records returned, this is used to protect our site if someone tries to attack our site
# and make it return huge amount of data
max_display_length = 500
def render_column(self, row, column):
return super(ProxyListJson, self).render_column(row, column)
def filter_queryset(self, qs):
# use parameters passed in GET request to filter queryset
qs_params = None
search = self.request.GET.get(u'sSearch', None)
if search: #模糊搜索
q = Q(ip__contains=search)|Q(description__contains=search)
qs_params = qs_params | q if qs_params else q
qs = qs.filter(qs_params)
return qs
URLS配置
url(r'^paging_proxy/$', ProxyListJson.as_view(), name='proxy_list_json'),
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。