How to send to records in data table pagination to

2019-09-15 04:06发布

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> 

Script

$("#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条回答
Deceive 欺骗
2楼-- · 2019-09-15 04:47

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

                }
              }); 
            });  
        });
查看更多
ゆ 、 Hurt°
3楼-- · 2019-09-15 04:57

See here: How can I select all checkboxes from all the pages in a jQuery DataTable

The answer should be the line:

var allPages = table.fnGetNodes();
查看更多
登录 后发表回答