Datatables merging Columns while exporting to Excel

45 Views Asked by At

enter image description here

In above Image on last column have td inside the td the problem is that when I am exporting it to excel via data tables then last two columns are not exporting and other columns are showing perfectly how can I merge these columns via data table to excels..

Table structure as follows

<table class="table table-bordered " id="example">
                        <thead>
                                <tr>
                                        <th>Branch ID</th>
                                        <th>Branch Name</th>
                                        <th>Date</th>
                                        <th>S.time</th>
                                        <th >E.time</th>
                                        <th>Lines</th>
                                        <th>
                                            <table>
                                                   <tr><th>Item</th></tr>
                                            
                                            </table>
                                        </th> <th>
                                            <table>
                                                    <tr><th>time</th></tr>
                                            </table>
                                        </th>

                                </tr>
                            </thead>       
                                <tbody>
                                                                                        <tr>
                                                   <td>1</td>
                                                   <td>HEAD OFFICE</td> 
                                                   <td id="tdtdate1"><input type="date" name="tdate" id="tdate1" class="tdate" value="2023-09-08"></td> 
                                                   <td class="td1"><input type="time" id="stime1" ></td>
                                                   <td><input type="time" id="etime1"></td>
                                                    <td><input type="number" name="number" id="number1" class="number" autocomplete="off" ></td>
                                                   <td >
                                                            <table><tr> <td> <input type="text" class="form-control item" id="item1"> </td></tr><tr> <td> <input type="text" class="form-control item" id="item1"> </td></tr><tr> <td> <input type="text" class="form-control item" id="item1"> </td></tr> </table></td>                               
                                                   <td ><table> <tr><td> <input type="text" class="form-control time" id="time10"> </td></tr> <tr><td> <input type="text" class="form-control time" id="time11"> </td></tr> <tr><td> <input type="text" class="form-control time" id="time12"> </td></tr> </table></td>                                                  
                                               </tr>        
                                                                                            <tr>
                                                   <td>2</td>
                                                   <td>ONLINE STORE</td> 
                                                   <td id="tdtdate1"><input type="date" name="tdate" id="tdate1" class="tdate" value="2023-09-08"></td> 
                                                   <td class="td1"><input type="time" id="stime1" ></td>
                                                   <td><input type="time" id="etime1"></td>
                                                    <td><input type="number" name="number" id="number1" class="number" autocomplete="off" ></td>
                                                   <td >
                                                            <table><tr> <td> <input type="text" class="form-control item" id="item1"> </td></tr><tr> <td> <input type="text" class="form-control item" id="item1"> </td></tr><tr> <td> <input type="text" class="form-control item" id="item1"> </td></tr> </table></td>                               
                                                   <td ><table> <tr><td> <input type="text" class="form-control time" id="time10"> </td></tr> <tr><td> <input type="text" class="form-control time" id="time11"> </td></tr> <tr><td> <input type="text" class="form-control time" id="time12"> </td></tr> </table></td>                                                  
                                               </tr>                                      
                                               </tr>        
                                                      
                                                
                                </tbody>

                     
                    </table>

Data Tables jquery as bellow

$(document).ready(function() {
    $('#example').DataTable( {
        info: false,
        ordering: false,
        paging: false
        dom: 'Bfrtip',
        buttons: [
        {
          extend: 'excel',
          exportOptions: {

            format: {
              body: function ( inner, rowidx, colidx, node ) {
                if ($(node).children("input").length > 0) {
                  return $(node).children("input").first().val();
                } else {
                  return inner;
                }
              }
            }
          }
        }
      ]
    } );
} );
0

There are 0 best solutions below