2010-05-25 11 views
27

¿Es posible cambiar el valor de configuración de jQuery DataTables en tiempo real? Mi problema es el siguiente, necesito cambiar sAjaxSource al vuelo. Ya hemos probado algo como esto:¿Cambiar el valor de configuración sobre la marcha?

var oDefault = { 
    "bServerSide": true, 
    "bProcessing": true, 
    "bJQueryUI": true, 
    "bLengthChange": false, 
    "bFilter": true, 
    "iDisplayLength": 8, 
    "sAjaxSource": "my.php?" + "idKat="+aData[3], 
    "aaSorting": [[ 0, "asc" ],[ 3, "asc" ]], 
    "sDom": '<"top"ir>t<"bottom"pf<"clear">', 
    "sPaginationType": "full_numbers", 
    "oLanguage": { 
     "sUrl": "<?php echo $full_path_jezik_2;?>" 
    }, 
    "aoColumns": [ 
     { "sName": "rb","sWidth": "15%", "sClass": "center","sType": "numeric" }, 
     { "sName": "chkZaBrisanje","sWidth": "20%", "sClass": "center", "bSortable":false }, 
     { "sName": "rbPrvaSlika","sWidth": "15%", "sClass": "center","bSortable":false }, 
     { "sName": "nazivSlike","sWidth": "50%", "sClass": "center", "sSortDataType": "dom-text" } 
    ] 
}; 

var oST = $.extend(true, {}, oDefault); 
oST.sAjaxSource = "my.php?" + "idKat="+aData[3]; 

alert(oST.sAjaxSource); 

if (typeof oTable == 'undefined') { 
    oTable = $("#my-table").dataTable(oST); 
} 
else 
{    
    oTable.fnDraw(); 
} 

Mi aData[3] se cambia al hacer clic.

Respuesta

45

Ha intentado

oTable = $("#my-table").dataTable(oST); 
var oSettings = oTable.fnSettings(); 
oSettings.sAjaxSource = "new value"; 
+1

tnx hombre, esto funciona, muchas gracias. – user147

+0

No funciona para mí, al menos no con 'bProcessing'. –

+2

No importa, es fnSettings(). OFeatures.bProcessing, pero parece fubar si se establece en false durante init. –

3

Puede utilizar la función fnReloadAjax(), consulte plug-ins en el sitio oficial de tabla de datos.

1

Para DataTables 1.10+: método

Uso ajax.url() API como se muestra a continuación para configurar la URL Ajax y cargar los datos de la nueva fuente de inmediato:

var table = $('#example').DataTable({ 
    ajax: 'data.json' 
}); 

table.ajax.url('newData.json').load(); 

Para DataTables 1,9:

Utilice el complemento fnReloadAjax() para volver a cargar los datos de la tabla de la fuente Ajax. Tenga en cuenta que este complemento ha quedado obsoleto.

Cuestiones relacionadas