Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <table id="users-table" class="table table-hover table-condensed" style="width:100%">
- <thead>
- <tr>
- <th><input type="checkbox" id="master"></th>
- <th>Category</th>
- <th>Description</th>
- <th>Number of Items</th>
- <th>Action</th>
- </tr>
- </thead>
- </table>
- <script type="text/javascript">
- $(document).ready(function() {
- oTable = $('#users-table').DataTable({
- "processing": true,
- "serverSide": true,
- "bProcessing":false,
- "bSort":false,
- "ajax": "{{ route('datatable.getcategories') }}",
- "columns": [
- {data: 'checkbox', name: 'checkbox', orderable: false, searchable: false},
- {data: 'name', name: 'name'},
- {data: 'action', name: 'action', orderable: false, searchable: false}
- ],
- });
- });
- </script>
- $stduents= Student::all();
- return Datatables::of($student)->addColumn('checkbox', function ($std) {
- return '<input type="checkbox" class="sub_chk" data-id="'.$std->id.'">';
- })->make(true);
- $("i[type='icon']").css('display','none'); //set style explicitly
- $('#master').on('click', function(e) {
- if($(this).is(':checked',true))
- {
- $(".sub_chk").prop('checked', true);
- } else {
- $(".sub_chk").prop('checked',false);
- }
- });
- $('.delete_all').on('click', function(e) {
- var allVals = [];
- $(".sub_chk:checked").each(function() {
- allVals.push($(this).attr('data-id'));
- });
- if(allVals.length <=0)
- {
- alert("Please select row.");
- }
- else {
- var check = confirm("Are you sure you want to delete this row?");
- if(check == true){
- var join_selected_values = allVals.join(",");
- $.ajax({
- url: $(this).data('url'),
- type: 'GET',
- headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
- data: 'ids='+join_selected_values,
- success: function (data) {
- if (data['success'])
- {
- $("#" + data['tr']).slideUp("slow");
- location.reload();
- alert(data['success']);
- }
- else if (data['error'])
- {
- alert(data['error']);
- }
- else
- {
- //alert('Whoops Something went wrong!!');
- }
- },
- error: function (data) {
- alert(data.responseText);
- }
- });
- $.each(allVals, function( index, value )
- {
- $('table tr').filter("[data-row-id='" + value + "']").remove();
- });
- }
- }
- });
- $('[data-toggle=confirmation]').confirmation({
- rootSelector: '[data-toggle=confirmation]',
- onConfirm: function (event, element) {
- element.trigger('confirm');
- }
- });
- $(document).on('confirm', function (e) {
- var ele = e.target;
- e.preventDefault();
- $.ajax({
- url: ele.href,
- type: 'GET',
- headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
- success: function (data) {
- if (data['success'])
- {
- $("#" + data['tr']).slideUp("slow");
- location.reload();
- alert(data['success']);
- }
- else if (data['error']) {
- alert(data['error']);
- }
- else
- {
- alert('Whoops Something went wrong!!');
- }
- },
- error: function (data) {
- alert(data.responseText);
- }
- });
- return false;
- });
- });
- </script>
- <script>
- $("input[type='checkbox']").click(function() {
- var atLeastOneChecked = false;
- $("input[type='checkbox']").each(function(index) {
- if ($(this).prop('checked'))
- atLeastOneChecked = true;
- });
- if (atLeastOneChecked) {
- $("i[type='icon']").show(); //built-in jquery function
- //...or...
- $("i[type='icon']").css('display','inline-block'); //or set style explicitly
- } else {
- $("i[type='icon']").hide(); //built-in jquery function
- //...or...
- $("i[type='icon']").css('display','none'); //set style explicitly
- }
- });
- </script>
Add Comment
Please, Sign In to add comment