dataTable.bootstrapTable({ url:'datatable/pasien', showColumns: true, showColumnsToggleAll: true, showRefresh: true, sortable: true, search: true, searchOnEnterKey: false, searchHighlight: false, pagination: true, pageSize: 10, pageList: [25, 50, 100, 200], cookie: true, icons: { refresh: "fas fa-sync", columns: "fas fa-th-list", }, columns: [ { title: "Name", field: "name", sortable: true, }, { title: "Tanggal Lahir", field: "birth", // tetap ambil dari field birth sortable: true, formatter: function(value, row, index) { if (!value) return '-'; const birthDate = new Date(value); const today = new Date(); let age = today.getFullYear() - birthDate.getFullYear(); const m = today.getMonth() - birthDate.getMonth(); if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { age--; // kalau bulan & tanggal belum lewat, umur dikurangi 1 } return row?.birth +' ('+ age +' Tahun)'; } }, { title: "Jenis Kelamin", field: "gender", sortable: true, }, { title: "Action", field: "uid", sortable: true, formatter: (value, row) => { let buttons = ""; buttons += ` ` buttons += ` ` return `
${buttons}
`; }, }, ], });