' +
' ' +
'
' + data + '
'
);
if (init_modal == 1) {
$(id).modal('show');
}
}
});
}
}
//Datatable
function start_datatables() {
var scroll = $(window).height() - $('.main-footer').height() - $('.nav-tabs-custom').height() - parseInt($('.nav-tabs-custom').css('margin-bottom'))*10 - $("#widget-controller_top").height();
if(scroll < 300) scroll = 300;
//Controlla che la tabella non sia giĆ inizializzata
if(!$.fn.DataTable.isDataTable('#main-records')){
//Parametri di ricerca da url o sessione
var search = getUrlVars();
$arr2){
if( $idx1 == "module_".$_SESSION['id_module'] ){
foreach( $arr2 as $field => $value ){
if( $value != '' ){
$field_name = str_replace( "search_", "", $field );
echo '
if(search["search_'.str_replace("__", "_", $field_name).'"] == undefined) {
search.push("search_'.str_replace("__", "_", $field_name).'");
search["search_'.str_replace("__", "_", $field_name).'"] = "'.$value.'";
}';
}
}
}
}
}
?>
var res = [];
$("#main-records th").each(function(){
var id = $(this).attr('id').replace("th_", "");
var done = false;
search.forEach(function(item, index, array){
if(item == "search_"+id.replace("__", "_")) {
res.push({ "sSearch" : array[item] });
done = true;
}
});
if(!done) res.push({ "sSearch" : "" });
});
var sum;
var id_module = $('#main-records').data('idmodule');
var table = $("#main-records").DataTable({
language: {
url: "/i18n/datatables/jquery.datatables.lang-.min.js"
},
autoWidth: true,
dom: "ti",
serverSide: true,
ordering: true,
searching: true,
aaSorting: [],
aoSearchCols: res,
scrollY: scroll,
scrollX: '100%',
scroller: {
loadingIndicator: true
},
ajax: {
url: "ajax_dataload.php?id_module="+id_module,
type: 'GET',
dataSrc: function(data){
sum = data;
return data.data;
}
},
initComplete: function() {
this.api().columns('.search').every( function () {
var column = this;
$("
")
.appendTo(column.header())
.on( 'keyup change', function (e) {
if (e.which != 9) {
if ($(this).val() == '') {
if($(this).parent().data("slow") != undefined) $("#slow").remove();
$(this).removeClass('input-searching');
$(this).next('.deleteicon').addClass('hide');
}
else {
if($(this).parent().data("slow") != undefined && $("#slow").length == 0){
$("#main-records_info").parent().append('
');
}
$(this).addClass('input-searching');
$(this).next('.deleteicon').removeClass('hide');
}
}
idx1 = 'module_'+( $('#main-records').data('idmodule') );
idx2 = 'search_'+( $(this).parent().attr('id') ).replace('th_', '');
//Imposto delle sessioni per le ricerche del modulo e del campo specificatsi
session_set( idx1+','+idx2, $(this).val(), 0 );
column
.search(this.value)
.draw();
});
});
//Disabilito l'ordinamento al click sull'
$("thead input, .deleteicon").click(function(e) {
stopTableSorting(e);
});
$('.deleteicon').on("click", function(e) {
reset($(this).parent().attr("id").replace("th_", ""));
});
//Se ho impostato una ricerca da URL filtro quei campi, altrimenti uso i campi della sessione
getUrlVars().forEach(function(item, index, arr) {
$('#th_'+item.replace("search_", "").replace("_", "__")+' input').val(arr[item]).trigger('keyup');
});
$arr2 ){
if( $idx1 == "module_".$_SESSION['id_module'] ){
foreach( $arr2 as $field => $value ){
if( $value != '' ){
$field_name = str_replace( "search_", "", $field );
echo "
if($('#th_".$field_name." input').val() == '') $('#th_".$field_name." input').val( \"".$value."\" ).trigger('keyup');\n";
}
}
}
}
}
?>
},
drawCallback: function(){
$(".dataTables_sizing .deleteicon").addClass('hide');
$("[data-background]").each(function(){
$(this).parent().css("background", $(this).data("background"));
});
$("[data-link]").each(function(){
$(this).parent().not('.bound').addClass('bound').click(function(event) {
if (event.ctrlKey) {
window.open($(this).find("[data-link]").data('link'));
} else {
location.href = $(this).find("[data-link]").data('link');
}
});
$(this).parent().addClass("clickable");
});
$("[data-color]").each(function(){
$(this).parent().css("color", $(this).data("color"));
});
},
footerCallback: function ( row, data, start, end, display ) {
var i =0;
this.api().columns().every( function () {
if(sum.summable[i] != undefined){
$(this.footer()).addClass("text-right");
$(this.footer()).html(sum.summable[i]);
}
else $(this.footer()).html(" ");
i++;
});
}
});
}
}
//Select
function start_superselect(){
//Statico
$('.superselect').each( function(){
$this = $(this);
$(this).select2({
theme: "bootstrap",
language: "it",
width: '100%',
allowClear: true,
escapeMarkup: function (text) { return text; }
});
});
//Dinamico (AJAX, per tabelle con molti record)
$('.superselectajax').each( function(){
$this = $(this);
$(this).select2({
theme: "bootstrap",
language: "it",
allowClear: true,
escapeMarkup: function (text) { return text; },
ajax: {
url: "/ajax_select2.php?op=" + $this.data('source'),
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term // search term
}
},
processResults: function (data) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
if($this.val() == "" || $this.val() == null){
data.forEach(function (item, index){
if(item.selected != undefined && item.selected != ""){
$this.append('
').val(item.id).trigger('change');
}
});
}
return {
results: data
}
},
cache: false
},
width: '100%'
});
});
$(".select2-selection__rendered").attr("title", "");
}
/**
* Aggiorna un