visible() behavior question

visible() behavior question

northamericannorthamerican Posts: 5Questions: 2Answers: 0

this code is working and toggles specified columns:

    table.column(".richMedia").visible( false );  
    $.each(data[0],function(index, value){
        if(value.indexOf("Dynamic") != -1){
            table.column(".richMedia.dynamic").visible( true );   
        }
        if(value.indexOf("Video") != -1){
            table.column(".richMedia.video").visible( true );   
        }
        if(value.indexOf("Image") != -1){
            table.column(".richMedia.image").visible( true );   
        }
    });

after refactoring:

    $.each(data[0],function(index, value){
        table.column(".richMedia.dynamic").visible((value.indexOf("Dynamic") != -1));
        table.column(".richMedia.video").visible(  (value.indexOf("Video") != -1));
        table.column(".richMedia.image").visible(  (value.indexOf("Image") != -1));
    });

it does not work even though they are pretty much logically the same or should have the same effect.
it seems i'm unable to toggle the visibility of each of these columns separately but rather together using the class '.richMedia'.
any ideas why the refactored code would not work?

thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Answer ✓

    I suspect it is because in your original code you were only setting the visibility if a positive state had been found. Now you are setting it every time in the loop.

    So consider you might have data[0] as [ 'Dynamic', 'Video' ] - it is going to loop twice, but only the Video state is going to be the active one, since it is setting the visibility of all three columns, regardless of what was set for Dynamic.

    Allan

This discussion has been closed.