You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.5 KiB
JavaScript
125 lines
4.5 KiB
JavaScript
function exportToExcel() {
|
|
let tableData = window._tblExport.innerHTML;
|
|
tableData = tableData.replace(/<A[^>]*>|<\/A>/g, ""); //remove if u want links in your table
|
|
tableData = tableData.replace(/<input[^>]*>|<\/input>/gi, ""); //remove input params
|
|
tableData = tableData + '<br /><br />Code witten By sudhir K gupta.<br />My Blog - https://comedymood.com'
|
|
|
|
let a = document.createElement('a');
|
|
a.href = `data:application/vnd.ms-excel, ${encodeURIComponent(tableData)}`
|
|
a.download = 'downloaded_file_' + getRandomNumbers() + '.xls'
|
|
a.click()
|
|
}
|
|
function getRandomNumbers() {
|
|
let dateObj = new Date()
|
|
let dateTime = `${dateObj.getHours()}${dateObj.getMinutes()}${dateObj.getSeconds()}`
|
|
|
|
return `${dateTime}${Math.floor((Math.random().toFixed(2) * 100))}`
|
|
}
|
|
_fullScreen();
|
|
function _loadData() {
|
|
var _lo = cssLoader();
|
|
AuditDevQuery(`SELECT kode,nama,kota,jk,telp,alamat FROM anggota`, function (a) {
|
|
var _tbl = '<table class="table table-bordered" width="100%">';
|
|
_tbl += '<thead>';
|
|
_tbl += '<tr>';
|
|
_tbl += `<th style="text-align:center;" rowspan="2">Urut</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">No.Induk</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">Nama</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">Temtala</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">Jenis Kelamin</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">NO.TELP</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">Alamat</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">Unit Kerja</th>`;
|
|
_tbl += `<th style="text-align:center;" rowspan="2">Tahun Masuk</th>`;
|
|
_master('simpanan', 'simpanan').forEach(function (e) {
|
|
_tbl += `<th style="text-align:center;" colspan="15">${e.text}</th>`;
|
|
})
|
|
_tbl += '</tr>';
|
|
_tbl += '<tr>';
|
|
_master('simpanan', 'simpanan').forEach(function (e) {
|
|
_tbl += `<th>Awal Tahun</th>`;
|
|
_month.forEach(function (m) {
|
|
_tbl += `<th>${m.text}</th>`;
|
|
})
|
|
_tbl += `<th>Tahun Berjalan</th>`;
|
|
_tbl += `<th>Akhir Tahun</th>`;
|
|
})
|
|
_tbl += '</tr>';
|
|
_tbl += '</thead>';
|
|
_tbl += '<tbody>'
|
|
var dataBody = a.map(function (v, i) {
|
|
var s = [];
|
|
|
|
s.push(i + 1);
|
|
s.push(v.kode);
|
|
s.push(v.nama);
|
|
s.push(`${v.kota},${tanggal(v.tgllahir).sekarang}`);
|
|
s.push(v.jk);
|
|
s.push(v.telp);
|
|
s.push(v.alamat);
|
|
s.push('-');
|
|
s.push(moment(v.masuk).format('MMM YYYY'));
|
|
_master('simpanan', 'simpanan').forEach(function (e) {
|
|
s.push((0).rp(0));
|
|
_month.forEach(function (m) {
|
|
s.push((0).rp(0));
|
|
})
|
|
s.push((0).rp(0));
|
|
s.push((0).rp(0));
|
|
});
|
|
return s;
|
|
});
|
|
console.log(dataBody);
|
|
_tbl += '</tbody>';
|
|
_tbl += '</table>';
|
|
|
|
_id('arealap').innerHTML = _tbl;
|
|
window._tblExport = el('div').html(_tbl).get();
|
|
|
|
setTimeout(() => {
|
|
window._tabel = $("#arealap table").DataTable({
|
|
dom: 'Bfrtip',
|
|
buttons: [
|
|
'copy',
|
|
{
|
|
title: 'Kekayaan Anggota',
|
|
extend: 'excelHtml5'
|
|
},
|
|
],
|
|
scrollX: true,
|
|
fixedColumns: {
|
|
left: 3
|
|
},
|
|
});
|
|
dataBody.forEach(function(d){
|
|
window._tabel.row.add(d);
|
|
});
|
|
_tabel.draw(false);
|
|
_lo.remove();
|
|
}, 100);
|
|
|
|
})
|
|
} _loadData();
|
|
|
|
(function dtButtons() {
|
|
var dt = document.querySelector('.dt-buttons');
|
|
if (dt == null) {
|
|
setTimeout(() => {
|
|
dtButtons();
|
|
}, 500);
|
|
} else {
|
|
Array.from(document.querySelector('.dt-buttons').children).forEach(function (e, i) {
|
|
_id('listreportmenu').appendChild(
|
|
el('a').addModule('actbut', e).addModule('as', i).click(function () {
|
|
if (this.as == 1) {
|
|
exportToExcel();
|
|
throw 'excel';
|
|
}
|
|
_tabel.buttons()[this.as].node.click();
|
|
}).href('#').class('dropdown-item').html(e.innerHTML).get()
|
|
)
|
|
});
|
|
|
|
}
|
|
})();
|