Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Trying to make use of jquery dataTable plugin for my application but i have an issue with it. If the table has two records, it shows the two records on the table and then shows "Showing 1 to 1 of 1 entries" . Also, i want to export the content to excel or copy to clipboard. It only copies or export just one row. For example , if my dataTable has four rows, it only copy just one row and i get to see "Showing 1 to 1 of 1 entries" at the footer

What I have tried:

JavaScript
$(document).ready(function () {

       $('#ex').dataTable({

           destroy: true,
           ordering: true,
            responsive: true,
            "paging": true,
            "bAutoWidth": false,
            "searching": true,
            dom: 'Bfrtip',
            buttons: [
       'copyHtml5',
       'excelHtml5',
       'csvHtml5',
       'pdfHtml5'
            ]
        });
     ;
    });
</script>





i have also added the following flies to it. Note: i'm using it in my asp.net application.






JavaScript
<script src="<%: ResolveUrl("plugins/datatables/jquery-3.2.1.js")%>"></script>
         <script src="<%: ResolveUrl("plugins/jQueryUI/jquery-ui.js")%>"></script>
<script src="<%: ResolveUrl("plugins/datatables/jquery.dataTables.min.js")%>"></script>
<link href="<%: ResolveUrl("plugins/datatables/jquery.dataTables.min.css")%>" rel="stylesheet" />
<link href="<%: ResolveUrl("plugins/datatables/button.dataTables.min.css")%>" rel="stylesheet" />
    <link href="<%: ResolveUrl("plugins/datatables/responsive.dataTables.min.css")%>" rel="stylesheet" />
      <script src="<%: ResolveUrl("plugins/datatables/dataTables.responsive.min.js")%>"></script>
<script src="<%: ResolveUrl("plugins/datatables/dataTables.bootstrap.js")%>"></script>
<script src="<%: ResolveUrl("plugins/datatables/dataTables.buttons.min.js")%>"></script>
<script src= "<%: ResolveUrl("plugins/datatables/buttons.flash.min.js")%>"></script>
<script src="<%: ResolveUrl("plugins/datatables/jszip.min.js")%>"></script>
<script src="<%: ResolveUrl("plugins/datatables/pdfmake.min.js")%>"></script>
<script src="<%: ResolveUrl("plugins/datatables/vfs_fonts.js")%>"></script>
<script src= "<%: ResolveUrl("plugins/datatables/buttons.html5.min.js")%>"></script>
<script src="<%: ResolveUrl("plugins/datatables/buttons.print.min.js")%>"></script>









C#
private void GenerateExcel(int coopId)
        {

            var coopmembers = coop.CoopMembers.Where(m => m.CoopId == coopId).ToList();
            var loanApplication = coop.LoanApplications.Where(m => m.LoanStatus == "Running").ToList();
            var query = (from c in coopmembers
                         join l in loanApplication on c.Member_Id equals l.MemeberId
                         select new
                         {
                             c.SubscriberCode,
                             c.FirstName,
                             c.LastName,
                             c.MiddleName,
                             l.ApplicationId,
                             l.MonthDeduction,

                         }).ToList();
            Repeater.DataSource = query;
            Repeater.DataBind();

        }



protected void Page_Load(object sender, EventArgs e)
        {
            int coopid = Convert.ToInt32(Session["CoopId"]);
            GenerateExcel(coopid);
        }
Posted
Updated 15-Aug-17 22:10pm
v3
Comments
j snooze 15-Aug-17 17:26pm    
I think we're missing some import information, like how you're binding the data to the datatable. Perhaps you have some malformed JSON or something so it can't tell the difference between where one record begins and ends.
Andy Lanng 16-Aug-17 4:12am    
see OP's response
Mcbaloo 16-Aug-17 4:38am    
i have updated my question with more source code. So i'm finding it hard to see why it can't tell the difference between where one record begins or end
Mcbaloo 16-Aug-17 3:36am    
i have updated my question with more source code. So i'm finding it hard to see why it can't tell the difference between where one record begins or end
Andy Lanng 16-Aug-17 4:11am    
You have to reply to peoples comments so that they will get a notification. Use the reply button on their comment

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900