如何将数据表中的记录分页发送到服务器类

时间:2017-02-04 09:32:47

标签: jquery pagination datatables

当我点击选择所有(超链接)选项或我想要特定页面中的特定记录(使用复选框)到服务器类时,我正试图在jQuery数据表中发送所有记录但问题是当我点击表单提交时按钮即导出PDF即使在jquery数据表分页中的其他页面中选择了记录,也只获取当前页面中的记录。

<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);

    });

      } );
         } );

enter image description here

2 个答案:

答案 0 :(得分:0)

见这里:How can I select all checkboxes from all the pages in a jQuery DataTable

答案应该是答案:

var allPages = table.fnGetNodes();

答案 1 :(得分:0)

我已经给了复选框的id,然后下面的代码正在为我工​​作

 $(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) {           

                }
              }); 
            });  
        });