Fail Export table to excel

Fail Export table to excel

armstrongearmstronge Posts: 10Questions: 2Answers: 0

Can someone help me, i've got table with 3 row data . when i try to export that table into excel it just appear in one row data . i dont know what is the problem i try to turn of the select function but nothing change at all. Please help me.

nb: Sorry for my bad english

<script type="text/javascript">
        $(document).ready(function() {
            $('#tableViewKuota').DataTable( {
                dom: 'Bfrtip',
                buttons: [
                    'copy', 'csv', 'excel', 'pdf', 'print'
                ]
            } );
        } );
</script>

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited August 2018

    Hi @armstronge ,

    I'm guessing an error occurred that interrupted the export - is there anything in the console? We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • armstrongearmstronge Posts: 10Questions: 2Answers: 0

    here's the running test case, and i thing i've got no issue in the console https://jsbin.com/hohomabuma/edit?html,console,output

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Thank you for the link. Can you show us the rendered HTML please (i.e. "View source")? The PHP code you've embedded there isn't going to execute, so we'd need to see what the generated HTML is.

    Allan

  • armstrongearmstronge Posts: 10Questions: 2Answers: 0
  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    At the end of every row in the body you have:


    </tr> </tbody>

    So the HTML being used isn't valid.

    If you change it so that the closing tbody tag is pesent only after all the body rows it should work as expected.

    Allan

  • armstrongearmstronge Posts: 10Questions: 2Answers: 0

    Dear @allan ,

    thx for your response. But i'm kinda confused, because in my html table tag i dont have <br>. Can you show me the right tag using commnent in this
    rendered HTML 'viewsource' http://live.datatables.net/tipaqede/1/edit

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    What Allan said is you have </tbody> at the end of each for, for example:

    End of row 1:

                <td>0</td>
                <td>0</td>
            </tr> 
              </tbody>
                    
      
            <tr>  
    <!--here showing results in the table -->  
    
                <td>STIKES MUHAMMADIYAH GOMBONG D3-KEPERAWATAN</td>  
    

    End of row 2:

               <td>0</td>
                <td>0</td>
            </tr> 
              </tbody>
                    
      
            <tr>  
    <!--here showing results in the table -->  
    
                <td>STIKES MUHAMMADIYAH GOMBONG S1-KEPERAWATAN</td>  
    

    Then the last row:

               <td>4</td>
                <td>4</td>
            </tr> 
              </tbody>
                     
    
            </table>
    

    You should have only one </tbody> at the end of your rows.

    Kevin

  • armstrongearmstronge Posts: 10Questions: 2Answers: 0

    hello @kthorngren,
    thx for your responds, now i know what is the problem. But can you give me a clue how to disable auto tag <tbody> when i catching array data from database phpmyadmin because <tbody> tag is auto regenerate based on query i have in phpmyadmin

    '''
    <tbody>
    <?php
    include("Db_kuota.php");
    $run=mysqli_query($dbkuota,"SELECT Nama_Univ, Nama_Stase,
    Sept1, Sept2, Sept3, Sept4,
    Okt1, Okt2, Okt3, Okt4,
    Nov1, Nov2, Nov3, Nov4, Nov5,
    Des1, Des2, Des3, Des4,
    Jan1, Jan2, Jan3, Jan4,
    Feb1, Feb2, Feb3, Feb4, Feb5,
    Mar1, Mar2, Mar3, Mar4,
    Apr1, Apr2, Apr3, Apr4,
    Mei1, Mei2, Mei3, Mei4, Mei5,
    Jun1, Jun2, Jun3, Jun4,
    Jul1, Jul2, Jul3, Jul4,
    Agt1, Agt2, Agt3, Agt4, Agt5
    FROM book_kuota
    INNER JOIN universitas ON book_kuota.Id_Univ = universitas.Id_Univ
    INNER JOIN stase ON book_kuota.Id_Stase = stase.Id_Stase
    WHERE book_kuota.Id_Stase='1'");//here run the sql query.

        while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.  
        {  
    
            $Universitas=$row[0];
            $Stase=$row[1]; 
            $Sept1=$row[2];  
            $Sept2=$row[3];  
            $Sept3=$row[4]; 
            $Sept4=$row[5];
            $Okt1=$row[6];
            $Okt2=$row[7];
            $Okt3=$row[8];
            $Okt4=$row[9];
            $Nov1=$row[10];
            $Nov2=$row[11];
            $Nov3=$row[12];
            $Nov4=$row[13];
            $Nov5=$row[14];
            $Des1=$row[15];
            $Des2=$row[16];
            $Des3=$row[17];
            $Des4=$row[18];
            $Jan1=$row[19];
            $Jan2=$row[20];
            $Jan3=$row[21];
            $Jan4=$row[22];
            $Feb1=$row[23];
            $Feb2=$row[24];
            $Feb3=$row[25];
            $Feb4=$row[26];
            $Feb5=$row[27];
            $Mar1=$row[28];
            $Mar2=$row[29];
            $Mar3=$row[30];
            $Mar4=$row[31];
            $Apr1=$row[32];
            $Apr2=$row[33];
            $Apr3=$row[34];
            $Apr4=$row[35];
            $Mei1=$row[36];
            $Mei2=$row[37];
            $Mei3=$row[38];
            $Mei4=$row[39];
            $Mei5=$row[40];
            $Jun1=$row[41];
            $Jun2=$row[42];
            $Jun3=$row[43];
            $Jun4=$row[44];
            $Jul1=$row[45];
            $Jul2=$row[46];
            $Jul3=$row[47];
            $Jul4=$row[48];
            $Agt1=$row[49];
            $Agt2=$row[50];
            $Agt3=$row[51];
            $Agt4=$row[52];
            $Agt5=$row[53];  
        ?>  
            <tr><!--here showing results in the table -->  
            <td><?php echo $Universitas; ?></td>  
            <td><?php echo $Stase; ?></td>  
            <td><?php echo $Sept1; ?></td>  
            <td><?php echo $Sept2; ?></td>  
            <td><?php echo $Sept3; ?></td> 
            <td><?php echo $Sept4; ?></td>
            <td><?php echo $JumSept; ?></td>
            <td><?php echo $Okt1; ?></td>
            <td><?php echo $Okt2; ?></td>
            <td><?php echo $Okt3; ?></td>
            <td><?php echo $Okt4; ?></td>
            <td><?php echo $JumOkt; ?></td>
            <td><?php echo $Nov1; ?></td>
            <td><?php echo $Nov2; ?></td>
            <td><?php echo $Nov3; ?></td>
            <td><?php echo $Nov4; ?></td> 
            <td><?php echo $Nov5; ?></td>
            <td><?php echo $JumNov; ?></td>
            <td><?php echo $Des1; ?></td>
            <td><?php echo $Des2; ?></td>
            <td><?php echo $Des3; ?></td>
            <td><?php echo $Des4; ?></td>
            <td><?php echo $JumDes; ?></td>
            <td><?php echo $Jan1; ?></td>
            <td><?php echo $Jan2; ?></td>
            <td><?php echo $Jan3; ?></td>
            <td><?php echo $Jan4; ?></td>
            <td><?php echo $JumJan; ?></td>
            <td><?php echo $Feb1; ?></td>
            <td><?php echo $Feb2; ?></td>
            <td><?php echo $Feb3; ?></td>
            <td><?php echo $Feb4; ?></td>
            <td><?php echo $Feb5; ?></td>
            <td><?php echo $JumFeb; ?></td>
            <td><?php echo $Mar1; ?></td>
            <td><?php echo $Mar2; ?></td>
            <td><?php echo $Mar3; ?></td>
            <td><?php echo $Mar4; ?></td>
            <td><?php echo $JumMar; ?></td>
            <td><?php echo $Apr1; ?></td>
            <td><?php echo $Apr2; ?></td>
            <td><?php echo $Apr3; ?></td>
            <td><?php echo $Apr4; ?></td>
            <td><?php echo $JumApr; ?></td>
            <td><?php echo $Mei1; ?></td>
            <td><?php echo $Mei2; ?></td>
            <td><?php echo $Mei3; ?></td>
            <td><?php echo $Mei4; ?></td>
            <td><?php echo $Mei5; ?></td>
            <td><?php echo $JumMei; ?></td>
            <td><?php echo $Jun1; ?></td>
            <td><?php echo $Jun2; ?></td>
            <td><?php echo $Jun3; ?></td>
            <td><?php echo $Jun4; ?></td>
            <td><?php echo $JumJun; ?></td>
            <td><?php echo $Jul1; ?></td>
            <td><?php echo $Jul2; ?></td>
            <td><?php echo $Jul3; ?></td>
            <td><?php echo $Jul4; ?></td>
            <td><?php echo $JumJul; ?></td>
            <td><?php echo $Agt1; ?></td>
            <td><?php echo $Agt2; ?></td>
            <td><?php echo $Agt3; ?></td>
            <td><?php echo $Agt4; ?></td>
            <td><?php echo $Agt5; ?></td>
            <td><?php echo $JumAgt; ?></td><br>
            </tr> 
            </tbody>
    

    '''

  • armstrongearmstronge Posts: 10Questions: 2Answers: 0

    here the source code of the php inside <tbody> tag http://live.datatables.net/tipaqede/4/edit

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    You've got the tbody closing tag inside the loop for the body row output. Move it outside of the loop.

    Allan

  • armstrongearmstronge Posts: 10Questions: 2Answers: 0

    Dear allan, kthorngren, and colin.

    Thanks for your help

This discussion has been closed.