Skip to content

Instantly share code, notes, and snippets.

@im-noob
Last active February 12, 2021 13:45
Show Gist options
  • Save im-noob/06abdc8e34d82f54c3f9e4746868f545 to your computer and use it in GitHub Desktop.
Save im-noob/06abdc8e34d82f54c3f9e4746868f545 to your computer and use it in GitHub Desktop.
Data Table Laravel snips
$(function () {
let data_table = $('#data-table');
let data_table_object = null;
fetch_data()
function fetch_data() {
if (data_table_object != null) {
data_table_object.destroy();
}
data_table_object = data_table.DataTable({
dom: 'rt<"bottom"flp><"clear">',
initComplete: function (settings, json) {
postLoad();
},
drawCallback: function () {
postLoad();
},
autoWidth: true,
processing: false,
serverSide: true,
aaSorting: [],
ordering: false,
ajax: {
url: "{{ route('manage-users.index-data') }}",
data: {
// 'project_id': $project_id,
// 'selected_status': $selected_status,
// 'selected_custom_roles': $selected_custom_roles
}
},
/*columnDefs: columnDefs,*/ // [{targets: Array(1), visible: false, searchable: false, bVisible: false, bSearchable: false}]
/*columns: column_list_datatable*/ // [{data: "health_alerts", mData: "health_alerts"}]
});
}
function postLoad() {
console.log('Data Table refreshed..');
}
/* for external Search button */
/*Datatable user Search */
search.on('keyup keydown change', function () {
$dataTable.search($(this).val()).draw();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment