Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding multi select for the DataTables #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
12,893 changes: 26 additions & 12,867 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.14.0",
"@popperjs/core": "^2.10.1",
"bootstrap": "^5.0.0-beta2",
"bootstrap-icons": "^1.4.0",
"datatables.net-bs5": "^1.10.25",
"datatables.net-responsive-bs": "^2.2.9",
"datatables.net-responsive-bs5": "^2.2.9",
"datatables.net-select": "^1.3.3",
"jquery": "^3.5.1",
"jquery-datatables-checkboxes": "^1.2.12",
"sweetalert2": "^11.0.11"
Expand Down
Binary file added public/.DS_Store
Binary file not shown.
8,188 changes: 8,185 additions & 3 deletions public/css/tlap.css

Large diffs are not rendered by default.

38,073 changes: 38,071 additions & 2 deletions public/js/tlap.js

Large diffs are not rendered by default.

Binary file added resources/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions resources/js/tlap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ try {

import 'bootstrap';
import 'datatables.net-bs5';
import 'datatables.net-select';
//import 'datatables.net-responsive-bs';
//import 'datatables.net-responsive-bs5';
//import 'jquery-datatables-checkboxes';
Expand Down
37 changes: 37 additions & 0 deletions resources/sass/dropdown.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}

.dropbtn:hover, .dropbtn:focus {
background-color: #2980B9;
}

.dropdown {
position: relative;
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown-content a:hover {background-color: #ddd}

.show {display:block;}
Binary file added resources/views/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion resources/views/layouts/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<!-- Styles -->
<link href="{{ asset('vendor/tlap/css/tlap.css') }}" rel="stylesheet">

@yield('styles')
</head>
<body>
<div class="container-fluid">
Expand Down
138 changes: 104 additions & 34 deletions resources/views/pages/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,133 @@
<h1>{{ $TLAPModel::getModelName() }}</h1>
</div>
<div class="col-md-9 d-flex justify-content-end ">
<a class="" href="/{{ config('tlap.path') }}/{{ $TLAPModel::getModelPluralName() }}/create" title="create"><i class="bi bi-plus"></i></a>
<a class="" href="/{{ config('tlap.path') }}/{{ $TLAPModel::getModelPluralName() }}/create"
title="create"><i class="bi bi-plus"></i></a>
</div>
</div>
@endsection

@section('content')
<div class="container" style="margin:15px auto">
<div class="d-none" id="showselected">
<p><b>Selected rows data</b></p>
<pre id="view-rows"></pre>
</div>
</div>
<div class="d-flex justify-content-end mb-3">
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Actions</button>
<div id="myDropdown" class="dropdown-content">
<a href="javascript:void(0)" id="consolelogids">Display all selected ids</a>
</div>
</div>
</div>
<table id="datatest" class="table display responsive nowrap" width="100%">
</table>
@endsection

@section('styles')
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css">
@endsection
@section('scripts')
<script>
$( document ).ready(function() {
$('#datatest').DataTable({
let mytable;
let rows_selected = [];
$(document).ready(function () {
mytable = $('#datatest').DataTable({
stateSave: true,
"scrollX": true,
"processing": true,
"serverSide": true,
"ajax": "{{ route('tlap.datatable', ['models' => $TLAPModel::getModelPluralName()]) }}",
'columnDefs': [
{{--{
'targets': 0,
'render': function(data, type, row, meta){
if(type === 'display'){
data = '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>';
}
'select': {
style: 'multi',
selector: 'td:first-child'
},
"columns": [ //try columnDefs
{
"defaultContent": "",
orderable: false,
className: 'select-checkbox',
targets: 0,
},

return data;
},
'checkboxes': {
'selectRow': true,
'selectAllRender': '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>'
}
},--}}
@foreach($TLAPModel::getDatatableFields() as $fieldName)
{
"targets": -1,
"data": null,
"defaultContent": "<button>Click!</button>"
}
],
"columns": [
@foreach($TLAPModel::getDatatableFields() as $fieldName)
{ "data": "{{ $fieldName }}", "title": "{{ $fieldName }}" },
@endforeach
{"data": "",
render : function(data, type, row) {
console.log(row);
"data": "{{ $fieldName }}", "title": "{{ $fieldName }}"
},
@endforeach
{
"data": "",
render: function (data, type, row) {
return '' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/show" class="show"><i class="bi bi-eye"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/edit" class="show"><i class="bi bi-pencil-square"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/delete" class="show"><i class="bi bi-trash"></i></a>' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/' + row.id + '/show" class="show"><i class="bi bi-eye"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/' + row.id + '/edit" class="show"><i class="bi bi-pencil-square"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/' + row.id + '/delete" class="show"><i class="bi bi-trash"></i></a>' +
''

} },
}
},
],
'order': [[1, 'asc']]

});
mytable.on('select', function (e, dt, type, indexes) {
if (type === 'row') {
var data = mytable.rows(indexes).data().pluck('id');
for (let i = 0; i < data.length; i++) {
if(!rows_selected.includes(data[i]))
{
rows_selected.push(data[i]);
}
}
}
});

mytable.on('draw', function (e, dt, type, indexes) {
var data = mytable.rows(indexes).data().pluck('id');
for (let i = 0; i < data.length; i++) {
if (rows_selected.includes(data[i])) {
$('#datatest tbody').find('tr').eq(i).addClass("selected");
}
}
});

mytable.on('deselect', function (e, dt, type, indexes) {
if (type === 'row') {
var data = mytable.rows(indexes).data().pluck('id');
var index = rows_selected.indexOf(data[0]);
rows_selected.splice(index,1);

}
});

$("#consolelogids").on('click', function (e) {
if (rows_selected.length) {
$("#showselected").removeClass("d-none");
$("#view-rows").text(rows_selected.map(function (elem) {
return elem;
}).join(","));
}
e.preventDefault();
})
});

function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}

// Close the dropdown menu if the user clicks outside of it
window.onclick = function (event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>
@endsection
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/Http/.DS_Store
Binary file not shown.