How to access to each rows().nodes() with $.fn.dataTable.Api ?
How to access to each rows().nodes() with $.fn.dataTable.Api ?
trucmuche2005
Posts: 71Questions: 22Answers: 2
Hello,
I have the following :
function initCompleteFunction(settings, json){
// I had this and it was working :
// var api = this.api();
// $( '.select2', api.rows().nodes() ).select2();
// now I have that :
var api = new $.fn.dataTable.Api( settings );
$( '.select2', api.rows().nodes() ).select2(); // and this line does not work anymore
// ... skipped ...
}
$(document).ready(function(){
$('#matable').on('xhr.dt', function ( e, settings, json, xhr ) {
initCompleteFunction(settings, json);
} );
var tableDONNEES = $("#matable").DataTable( {
// ... skipped ...
});
});
How can I modify the $( '.select2', api.rows().nodes() ).select2();
to get it working when the table is initialized and when reloaded using tableDONNEES.ajax.reload(null, false);
?
Many thanks in advance for your help,
T.
This discussion has been closed.
Answers
That looks like the perfect way to me.
If that isn't working for you, can you link to a test case showing the issue, as requested in the forum rules please?
Allan
Thank you Allan ! Yes of course. I send to you by PM login & password to access my website...
Ah! I see. Thanks for the link. Try this:
Since we need to have the elements in the DOM before they can be manipulated, we have to wait for the
draw
event.You could possibly change it to just listen for
draw.dt
rather thanxhr.dt
. I think its really up to yourself. It would probably be easier that way:You just need to be a little more careful since that will be executed on every draw.
Allan
Waw. I used your first solution and it works perfectly ! :-) Now I have a subsequent question here Many many thanks again !!