如何将数据表中的记录分页发送到服务器类 [英] How to send to records in data table pagination to the server class
本文介绍了如何将数据表中的记录分页发送到服务器类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我单击全选(超链接)选项或希望将特定页面中的特定记录(使用复选框)发送到服务器类时,我试图将所有记录与jQuery数据表一起发送,但是问题是当我单击表单提交时即使在jquery数据表的分页中的其他页面中选择了记录,导出PDF"按钮也只能从当前页面获取记录.
I'm trying to send all records with in a jQuery data table when I click select all(hyperlink) option or I want particular records in particular pages(using checkbox) to server class but the problem is when I click form submit button I.e Export PDF am getting only the records from current page even though records selected in other pages in jquery data table pagination.
<s:form id="downloadStudentDetailsForm" action="downloadStudentDetails" theme="css_xhtml" cssClass="form-horizontal">
<div class="dataTable_wrapper">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTS">
<thead>
<tr>
<th><a href="#" id="selectall">Select all</a></th>
<th>Student Name</th>
<th>Parent Phone</th>
<th>Parent Email</th>
<th>ReferenceID</th>
</tr>
</thead>
<tbody>
<s:iterator value="studentRecords">
<tr>
<td><s:checkbox name="students" cssClass="case chkPassport" fieldValue="%{studentname+' '+phone+' '+email+' '+ref}" /></td>
<td><s:property value="studentname" /></td>
<td><s:property value="phone" /></td>
<td><s:property value="email"></td>
<td><s:property value="ref" /></td>
</tr>
</s:iterator>
</tbody>
</table>
</div>
<div class="col-xs-1 ">
<s:submit cssClass="btn btn-success" value="Export to Excel" id="exl" action="downloadStudentsListINExcel" />
</div>
<div class="col-xs-3 ">
<s:submit cssClass="btn btn-danger" value="Export to PDF" id="pdf" action="downloadStudentsListInPDF" />
</div>
</s:form>
脚本
$("#selectall").click(function() {
var rows = table.rows({ 'search': 'applied' }).nodes();
debugger;
if($('.case:checkbox:checked', rows).length == rows.length){
$('.case', rows).prop('checked', false);
}
else{
$('.case', rows).prop('checked', true);
}
$('#dvcount').html($(rows).find(".case:checkbox:checked").length);
$("body").on("change","input",function() {
var rows = table.rows({ 'search': 'applied' }).nodes();
$('#dvcount').html($(rows).find(".case:checkbox:checked").length);
});
} );
} );
推荐答案
我为复选框指定了ID,然后下面的代码对我有用
I have given id for the check box then below code is working for me
$(document).ready(function() {
$('#yourDataTableID').DataTable();
$("#button").click(function() {
var chcklist = new Array();
var oTable = $('#yourDataTableID').dataTable();
var rowcollection = oTable.$("#checkboxID:checked", {"page": "all"});
rowcollection.each(function(index,elem) {
chcklist.push($(elem).val());
});
$.ajax({
type : 'POST',
url: "/DataTableQuery/checkPaginatedData",
dataType : 'JSON',
data : {list: chcklist},
success : function(data, success) {
}
});
});
});
这篇关于如何将数据表中的记录分页发送到服务器类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文