Skip to content

Instantly share code, notes, and snippets.

@hkkcngz
Created August 31, 2023 06:12
Show Gist options
  • Save hkkcngz/5d8bf7d052111f465c11a83bb1167b57 to your computer and use it in GitHub Desktop.
Save hkkcngz/5d8bf7d052111f465c11a83bb1167b57 to your computer and use it in GitHub Desktop.
Bootstrap-table Generator
function generateBootstrapTable($id, $columns, $dataUrl, $extensions = []) {
$tableHtml = "<table id='$id' class='table table-striped'";
// Temel ayarlar
$tableHtml .= ' data-id-field="id" data-unique-id="id" data-toolbar="#toolbar"';
// Eklentileri ve özellikleri ekleyin
foreach($extensions as $key => $value) {
$tableHtml .= ' data-' . $key . '="' . $value . '"';
}
// Tabloyu tamamlayın
$tableHtml .= "></table>";
// Javascript kodu oluştur
$jsCode = "<script defer>
let dataForTable = {};
document.addEventListener('DOMContentLoaded', async (event) => {
dataForTable = await fetchData('$dataUrl');
$('#" . $id . "').bootstrapTable({
data: dataForTable,
pagination: true,
search: true,
columns: " . json_encode($columns) . "
});
});
</script>";
return $tableHtml . $jsCode;
}
@hkkcngz
Copy link
Author

hkkcngz commented Aug 31, 2023

Yeni Ekle
'id', 'title' => 'ID'], ['field' => 'username', 'title' => 'Kullanıcı Adı'], ['field' => 'rol', 'title' => 'Rol', 'formatter' => 'roleFormatter'], ['field' => 'aktivasyon', 'title' => 'Aktivasyon', 'formatter' => 'activationFormatter'], ['field' => 'eylem', 'title' => 'Eylem', 'align' => 'center', 'formatter' => 'actionsAddDeleteBtn', 'events' => 'window.actionsEvents'] ]; echo generateBootstrapTable('tableUyeler', $columns, 'uyeler'); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment