Langkah 1
Terlebih dahulu, buatlah sebuah file untuk menampilkan data dari database MySQL. Pastikan data yang ditampilkan dalam bentuk tabel. Misal seperti berikut.index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <table id="tabelExport"><thead><tr><th width="7%">No.</th><th width="30%">Nama</th><th width="40%">Kota Asal</th><th width="23%">No. Hp</th></tr></thead><tbody><?php $i = 1;$query = mysql_query("SELECT * FROM karyawan ");while($fetch = mysql_fetch_array($query)) {?><tr><td><?php echo $i; ?></td><td><?php echo $fetch['nama_karyawan']; ?></td><td><?php echo $fetch['kota_asal']; ?></td><td><?php echo $fetch['hp']; ?></td></tr><?php $i++; } ?></tbody></table><button id="tombolExport">Export Excel</button> |
Berilah id pada tabel dan tombol yang telah dibuat. Pada contoh diatas id tabel tabelExport dan id tombol tombolExport.
Langkah 2
Sisipkan plugin jQuery beserta plugin ExcelExport ke dalam dokumen file diatas.1 2 3 | <script src="js/jquery-2.0.1.min.js"></script><script src="js/jquery.base64.js"></script><script src="js/jquery.btechco.excelexport.js"></script> |
1 2 3 4 5 6 7 8 | $(document).ready(function () { $("#tombolExport").click(function () { // Jika tombol export diklik $("#tabelExport").btechco_excelexport({ // Definisikan tabel yang akan di export containerid: "tabelExport" , datatype: $datatype.Table }); });}); |
No comments:
Post a Comment