527 messaggi dal 18 dicembre 2012
Ciao a tutti
Ho questo codice che mi crea un datatable in un file esterno .js:

var TableManaged = function () {

return {

//main function to initiate the module
init: function () {

if (!jQuery().dataTable) {
return;
}

// begin table
oTable = $('#dtElenco').dataTable({
"oLanguage": {
"sUrl": "/Metronic/plugins/data-tables/language/it-IT.txt"
},
"aoColumns": [
{ "bSortable": false },
{ "bSortable": false },
null,
null,
null,
null,
null,
{ "bSortable": false }
],
"aaSorting": [[3, "asc"]],
"aLengthMenu": [
[5, 15, 20, -1],
[5, 15, 20, "Tutti"] // change per page values here
],
// set the initial value
"iDisplayLength": 5,
"sPaginationType": "bootstrap",
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [0] },
{ "bSearchable": false, "aTargets": [0] }
]
});

jQuery('#dtElenco .group-checkable').change(function () {
var set = jQuery(this).attr("data-set");
var checked = jQuery(this).is(":checked");
jQuery(set).each(function () {
if (checked) {
$(this).attr("checked", true);
$(this).parents('tr').addClass("active");
} else {
$(this).attr("checked", false);
$(this).parents('tr').removeClass("active");
}
});
jQuery.uniform.update(set);
});

jQuery('#dtElenco').on('change', 'tbody tr .checkboxes', function () {
$(this).parents('tr').toggleClass("active");
});

jQuery('#dtElenco_wrapper .dataTables_filter input').addClass("form-control input-medium input-inline"); // modify table search input
jQuery('#dtElenco_wrapper .dataTables_length select').addClass("form-control input-xsmall input-inline"); // modify table per page dropdown
//jQuery('#dtElenco_wrapper .dataTables_length select').select2(); // initialize select2 dropdown


// ChangeStatus
$('#dtElenco').on('click', '[id*="btnStatus"]', function () {
var btnStatus = $(this);
var id = btnStatus.attr('data-id');

if ($.trim(id) != '') {
$.ajax({
url: '/Handler/ajaxOperation.ashx',
data: { type: 'changeStatusStrutturaContatto', id: id },
cache: false,
async: false,
dataType: 'json',
type: 'POST',
error: function (request, error) {
$('.alert-danger', $('.form-data')).show();
$('.alert-danger', $('.form-data')).find('span').html('Impossibile completare l\'operazione');
},
success: function (response) {
if (response.msg_error != '') {
$('.alert-danger', $('.form-data')).show();
$('.alert-danger', $('.form-data')).find('span').html(response.msg_error);
}
else {
oTable.api().ajax.reload();
//location.reload();
}
}
});
}
});
// fine ChangeStatus
}

};

}();

Quando eseguo oTable.api().ajax.reload(); (ho anche provato con oTable.ajax.reload(); e $('#dtElenco').dataTable().api().ajax.reload();) non fa nulla è ricevo questo errore:
TypeError: oTable.ajax is undefined

oTable.ajax.reload();

Prima utilizzavo oTable.fnReloadAjax(); su un altro template e non avevo problemi, ora utilizzo metronic e ho problemi.
da cosa può dipendere?
Grazie mille
11.886 messaggi dal 09 febbraio 2002
Contributi
ciao,
secondo la documentazione, il metodo corretto dovrebbe essere proprio oTable.ajax.reload()

Tuttavia tu hai un errore e quindi dobbiamo fare qualche indagine per capire dov'è il problema.
Per prima cosa, metti questa riga di codice subito prima della tua istruzione di reload.
console.log(oTable);


Questo farà apparire nella console del tuo browser (a cui puoi accedere con il tasto F12) l'oggetto referenziato dalla variabile oTable. Se è null o undefined, ecco trovato il problema: la variabile non è (più) legata alla DataTable.
Se invece vedi apparire un oggetto, puoi cominciare ad ispezionarlo per verificare che effettivamente al suo interno ci sia una proprietà chiamata ajax, che a sua volta ha un metodo reload.

Gli strumenti di sviluppo del browser ti consentono anche di debuggare il javascript. Per problemi come questo penso sia ideale, perché ti permette di congelare l'esecuzione del codice lato client affiché tu possa vedere il contenuto di ogni variabile.

ciao,
Moreno

Enjoy learning and just keep making
527 messaggi dal 18 dicembre 2012
Ciao e grazie
in effetti non c'è la funzione e non capisco perchè dato che se solo stesso codice lo inserisco in una pagina asp.net funziona

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.