rows().nodes() selector to get all cells of a column given by name

rows().nodes() selector to get all cells of a column given by name

trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

Hello,

I would like to access each cell of the column named by {name: 'option'} using "columns" parameter to make something like

$(document).ready(function() {
$('#tableMDS').on('xhr.dt', function ( e, settings, json, xhr ) {
        initCompleteFunction(settings, json);
    } );
...
});
function initCompleteFunction(settings, json){
var api = new $.fn.dataTable.Api( settings );
$( '.myclass', api.rows().nodes() ).something();   // HERE but only for the cells in the 'option' column and not for all cells of the datatable
}

I did not found out how to do this. Could you help me please ?

Many thanks in advance.

T.

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    you are probably using the wrong event.

    column render or createdRow. Let us know what you are trying to do to the row/column we probably could come up with a better recommendation

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    Use cells().every() with a suitable column selector:

    table.cells( null, 'salary:name' ).every( function () {
      ...
    } );
    

    Allan

  • trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

    Thank you very much. I got this which works perfectly now (thanks again !) :

    $('#matable').on('xhr.dt', function ( e, settings, json, xhr ) {
        new $.fn.dataTable.Api( settings ).one( 'draw', function () {
          initCompleteFunction(settings, json);
        } );
    } );
    

    but I can't manage to make the following working :

    function initCompleteFunction(settings, json){
    var api = new $.fn.dataTable.Api( settings );
    api.cells(null, 'statut:name').every(function(){
            $( '.select2', this ).select2(); // This doesn't work
        });
    ...
    

    I tried $( '.select2', $(this) ).select2();, $( '.select2', this.to$() ).select2();but nothing works...

    Could you help me please once again (I think it's my last question for a moment :-)) ?
    Many many thanks in advance !

    T.

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    this is not a node so no, that wouldn't work.

    You'd need to use cells().nodes() to get the nodes. For example:

    api.cells( null, 'statut:name' ).nodes().to$().select2();
    

    Allan

  • trucmuche2005trucmuche2005 Posts: 71Questions: 22Answers: 2

    Thank youuuuu Allan ! :-) Many many thanks !

This discussion has been closed.