Skip to content

Instantly share code, notes, and snippets.

@im-noob
Created May 26, 2021 07:37
Show Gist options
  • Save im-noob/665b36cd2af23a4bb623e7277cab302b to your computer and use it in GitHub Desktop.
Save im-noob/665b36cd2af23a4bb623e7277cab302b to your computer and use it in GitHub Desktop.
DataTable Setting On Same Config where it was
function fetch_data($project_id) {
progress_bar_start();
visible_column_list = [];
columnDefs = [];
/*Extracting Column name from List*/
column_filter.each(function () {
visible_column_list.push({'data': $(this).val()});
});
column_list_datatable = visible_column_list.concat(hidden_column);
/*for profile pic cut paste in init function */
user_list_column_index = column_list_datatable.length - hidden_column.length;
for (let i = column_list_datatable.length - hidden_column.length; i < column_list_datatable.length; i++) {
/*checking if searchable are true*/
if (hidden_column_searchable_index.includes(column_list_datatable[i].data)) {
columnDefs.push({targets: [i], visible: false, searchable: true});
} else {
columnDefs.push({targets: [i], visible: false, searchable: false});
}
}
/*making all visible column searchable false*/
visible_column_list.forEach(function (value, key) {
columnDefs.push({targets: [key], searchable: false});
});
if ($dataTable != null) {
$dataTable.destroy();
}
/*pushing selected Project ID*/
manage_users_selected_url = manage_users_selected_url.replace(':project_id', $project_id);
$dataTable = data_table.DataTable({
dom: 'rt<"bottom"flp><"clear">',
initComplete: function (settings, json) {
setTimeout(function () {
refreshUserList();
$('#data-table_paginate-outside').html('');
$('#data-table_paginate').appendTo('#data-table_paginate-outside');
progress_bar_stop();
})
},
drawCallback: function () {
progress_circle.circleProgress('duration', 100);
progress_circle.circleProgress('value', 1.0).on('circle-animation-progress', function (event, progress) {
$(this).find('strong').html(100 + '<i>%</i>');
});
setTimeout(function () {
refreshUserList();
progress_bar_stop();
});
// /*Hide processing */
progress_circle.circleProgress('duration', 100);
progress_circle.circleProgress('value', 1.0).on('circle-animation-progress', function (event, progress) {
$(this).find('strong').html(100 + '<i>%</i>');
});
/* add only when no child */
},
/* this will save the setting */
bStateSave: true,
fnStateSave: function (oSettings, oData) {
localStorage.setItem('offersDataTables', JSON.stringify(oData));
},
fnStateLoad: function (oSettings) {
return JSON.parse(localStorage.getItem('offersDataTables'));
},
autoWidth: true,
processing: false,
oLanguage: {
sProcessing: loading_image_element
},
serverSide: true,
aaSorting: [],
ordering: false,
ajax: {
xhr: function () {
var xhr = new window.XMLHttpRequest();
let duration_change = true;
//Download progress
xhr.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
let percentComplete = evt.loaded / evt.total;
//Do something with download progress
if (duration_change) {
progress_circle.circleProgress('duration', 100);
duration_change = false;
}
$('.progress-bar-info').text('We are almost there.');
let percentage_to_show = 0.8 + percentComplete * 0.2;
// console.log(percentage_to_show);
progress_circle.circleProgress('value', percentage_to_show).on('circle-animation-progress', function (event, progress) {
$(this).find('strong').html(Math.round(percentage_to_show * 100) + '<i>%</i>');
});
}
}, false);
return xhr;
},
url: "{{ route('index-data') }}",
data: {
'project_id': $project_id,
'selected_status': $selected_status,
'selected_custom_roles': $selected_custom_roles
},
type: "GET"
},
columnDefs: columnDefs,
columns: column_list_datatable,
lengthChange: false,
bInfo: false,
pageLength: 5,
language: {
emptyTable: '<p class="pb-2 pt-4" style="display: block" id="no-record-box-table">' +
'No records found' +
'</p>',
processing: loading_image_element
}
});
$dataTable.on('xhr', function (e, settings, json) {
setTimeout(function () {
if (
json.data.length === 0 &&
search.val().length === 0 &&
filtered_column_ids.length === 0 &&
$selected_custom_roles.length === 0 &&
$selected_status.length === 0
) {
$('.dataTables_empty').html('<a class="py-4" style="display: block" ' +
'href="' + manage_users_selected_url + '">' +
'Please add users to this project' +
'</a>');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment