gpt4 book ai didi

Jquery数据表分页

转载 作者:行者123 更新时间:2023-12-01 01:54:35 26 4
gpt4 key购买 nike

在下面的代码中,html 加载并将调用 group_map set python 函数。我的问题是系统中启用了分页,因此如果第 3 页中的用户删除了条目,页面将重新加载并返回到第 1 页.删除条目后如何让用户留在同一页面

使用的数据表来自http://www.datatables.net/

                 <html>
<head>
<link rel="stylesheet" type="text/css" href="css/datatable.css" />
<script type="text/javascript" src="js/jquery.dataTables.js"></script>
</head>
<script>
var oTable;

function fnFormatDetails ( nTr )
{
var iIndex = oTable.fnGetPosition( nTr ) ;
var aData = oTable.fnSettings().aoData[iIndex]._aData;

var sOut = aData[6];

return sOut;
}

$(document).ready(function() {
$.ajaxSetup({ cache: false });
oTable = $('#s_group_table').dataTable( {
"aoColumns": [
{"sWidth": "30%" },
{"sWidth": "20%" },
{"bSortable": false,"sWidth": "5%" },
{"bSortable": false,"sWidth": "5%" },
],
"aaSorting": [[0, 'desc']],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/repo/group_set/",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bFilter": false,
"oLanguage" : { "sZeroRecords": "No data found", "sProcessing" : "Fetching Data" }
});

});


function delete_set(id)
{
$.post("/repo/group_set_delete/" + id) ;
oTable.fnDraw(true) ;
location.reload();
}
</script>

<div id="s_group_table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th width="30%">Name</th>
<th width="30%"></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" class="dataTables_empty">No data found</td>
</tr>
</tbody>
</table>
</div>





def group_set(request):
try:
response_dict = {}
offset = int(request.GET.get('iDisplayStart'))
limit = int(request.GET.get('iDisplayLength')) + offset
echo = request.GET.get('sEcho')

sort_cols = int(request.GET.get('iSortingCols'))
for i in range(0, sort_cols):
dir = request.GET.get('iSortDir_' + str(i))
if dir == "asc":
dir = ""
else:
dir = "-"
order_by = dir + group_map (request.GET.get('iSortCol_' + str(i))) + ","

order_by = order_by.strip(',')


total = GroupSet.objects.filter(pk=request.profile.my_id).count()
if limit > total:
limit = total

if order_by == "":
groupset = GroupSet.objects.filter(pk=request.profile.my_id)[offset:limit]
else:
groupset = GroupSet.objects.filter(pk=request.profile.my_id).order_by(order_by)[offset:limit]

p_array = []
p_array_o = []
for q in studentprofilegroup_map:
delete_l = "<a><img title='Delete group' class=center src=\"/repo/images//del.gif\" onclick=javascript:delete_set(\"%d\")></a>&nbsp;" % (q.id)

emp_name = q.first_name + q.last_name

p_array_o = [emp_name , delete_l ]
p_array.append(p_array_o)
response_dict.update({'sEcho': echo, 'iTotalRecords': total, 'iTotalDisplayRecords': total, 'aaData': p_array}) ;

return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')
except:
print "No records found"

删除功能如下

   def group_set_delete(request,gid):
try:
s_gp = GroupSet.objects.filter(pk=gid)
s_gp.delete()
except:
print "could not be deleted"

最佳答案

我以不同的方式遇到了同样的问题。在我更新第 3. 页中的行后,该表过去常常自动返回到第 1. 页。 fnUpdate 的第四个参数采用 true/false 来更新表,默认值为 true。我把它改成 false 然后它就开始工作了。与您遇到的情况不完全相同,但可能有助于解决您的问题。查看您在代码中使用的函数的参数。问候。奥兹莱姆。

$('#rulesTable').dataTable().fnUpdate(suburb_name, rowNo, 3, false );

关于Jquery数据表分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3572359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com