php и ajax поиск и экспорт по отдельным столбцам, чтобы превзойти и сделать PDF - PullRequest
0 голосов
/ 07 апреля 2020

Я закодировал поиск по отдельному столбцу и экспортировал эти искомые данные в Excel. Здесь я использовал сценарии php и ajax, этот код влияет только на одну строку данных, которую он ищет, и экспортирует только первую первую строку данных.

это мой код,

PHP код

  <table id="example" class="display nowrap" width="100%">
    <thead>


      <tr>
         <th>service num</th>
          <th>year</th>
          <th>Month</th>
          <th>Date</th>
          <th>Time in</th>
          <th>Time out</th>
          <th>Location</th>
          <th>Work done</th>
          <th>v no</th>
          <th>distance</th>
          <th>Tra charges</th>
          <th>Subsistence</th>
          <th>Night allowance</th>
          <th>OT Hours</th>
          <th>edit</th>
          <th>edit</th>


      </tr>


      <tr>
        <th class="filterhead">service num</th>
          <th class="filterhead">year</th>
          <th class="filterhead">Month</th>
          <th class="filterhead">Date</th>
          <th class="filterhead">Time in</th>
          <th class="filterhead">Time out</th>
          <th class="filterhead">Location</th>
          <th class="filterhead">Work done</th>
          <th class="filterhead">v no</th>
          <th class="filterhead">distance</th>
          <th class="filterhead">Tra charges</th>
          <th class="filterhead">Subsistence</th>
          <th class="filterhead">Night allowance</th>
          <th class="filterhead">OT Hours</th>
          <th class="filterhead">OT Hours</th>
          <th>edit</th>
      </tr>
    </thead>
 <tbody>
    <tr> 
        <td><?php echo $row['service_nu']  ?></td>
        <td ><?php echo $row['year']; ?></td>
        <td><?php echo $row['month']  ?></td>
        <td><?php echo $row['date1']  ?></td>
        <td><?php echo $row['time_in']  ?></td>
        <td><?php echo $row['time_out']  ?></td>
        <td><?php echo $row['location']  ?></td>
        <td><?php echo $row['work_done']  ?></td>
        <td><?php echo $row['vehicle_no']  ?></td>
        <td><?php echo $row['distance']  ?></td>
        <td><?php echo $row['travelling_charges']  ?></td>
        <td><?php echo $row['subsistence']  ?></td>
        <td><?php echo $row['night_allowance']  ?></td>
        <td><?php echo $row['ot_hours']  ?></td>

        <td>

          <button type="button" class="btn btn-success editbtn" data-toggle="modal" data-target="                 #EditAttendance">

                 Edit

          </button>

    </td>
    <td>

         <button type="button" class="btn btn-danger deletebtn" data-toggle="modal" data-target="#deleterecord">
                Delete
            </button>

    </td>


     </tr>

  </table>

</div>

Это ajax код

$ (документ) .ready (function () {

var table = $ ('# example'). DataTable ({orderCellsTop: true, dom: 'Bfrtip' , scrollX: true, кнопки: ['copy', 'csv', 'excel', 'pdf', 'print'], initComplete: function () {var api = this.api (); $ ('. filterhead' , api.table (). header ()). each (function (i) {var column = api.column (i); var select = $ ('') .appendTo ($ (this) .empty ()). on ('change', function () {var val = $ .fn.dataTable.util.escapeRegex ($ (this) .val ());

                    column
                        .search( val ? '^'+val+'$' : '', true, false )
                        .draw();
                } );

            column.data().unique().sort().each( function ( d, j ) {
                select.append( '<option value="'+d+'">'+d+'</option>' );
            } );
        } );
    }
} );
});

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...