如何将数据表分页中的记录发送到服务器类 [英] How to send to records in data table pagination to the server class

查看:15
本文介绍了如何将数据表分页中的记录发送到服务器类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<div class="dataTable_wrapper"><table width="100%" class="table table-striped table-bordered table-hover" id="dataTS"><头><tr><th><a href="#" id="selectall">全选</a></th><th>学生姓名</th><th>家长电话</th><th>家长电子邮件</th><th>ReferenceID</th></tr></thead><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:迭代器></tbody>

<div class="col-xs-1"><s:submit cssClass="btn btn-success" value="导出到 Excel" id="exl" action="downloadStudentsListINExcel"/>

<div class="col-xs-3"><s:submit cssClass="btn btn-danger" value="导出为 PDF" id="pdf" action="downloadStudentsListInPDF"/>

</s:form>

脚本

$("#selectall").click(function() {var rows = table.rows({ 'search': 'applied' }).nodes();调试器;if($('.case:checkbox:checked', rows).length == rows.length){$('.case', rows).prop('checked', false);}别的{$('.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 然后下面的代码对我有用

 $(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({类型:'POST',url: "/DataTableQuery/checkPaginatedData",数据类型:'JSON',数据:{列表:清单},成功:功能(数据,成功){}});});});

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

    });

      } );
         } );

解决方案

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屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆