Visibility false target using a variable

Visibility false target using a variable

pdxbugpdxbug Posts: 2Questions: 1Answers: 0

I'm trying to merge two columns and then set the visibility of the merged column to false. The target will be dynamically set depending upon which column is merging, as I may want to merge more than one column. Anyways, I can get the variable to work only if I make some changes to it, i.e. var index+1-1. See the code below. It is messy having to do it this way. How can I just use the var index without changing it for the target?

$('#download_content').DataTable({
colReorder: true,
'bServerSide': false,
'lengthMenu': [[-1, 25, 50, 100], ['All', 25, 50, 100]],
'language': {
'lengthMenu': 'Show Entries MENU per Page'
},
'columnDefs': [
{
// The data parameter refers to the data for the cell (defined by the
// data option, which defaults to the column being worked with, in
// this case data: 0.
'render': function ( data, type, row ) {
var mergeinfo;
if(data==''&&row[index]!=''){
mergeinfo = row[index];
} else if(data!=''&&row[index]==''){
mergeinfo = data;
} else if(data!=''&&row[index]!=''){
mergeinfo = data+', '+row[index];
} else if(data==''&&row[index]==''){
mergeinfo = data;
}
return mergeinfo;
},
'targets': index-1
},
{
'visible': false,
'targets': index-1+1 <---- HERE. If I just put index, it will not hide on the merge. With the -1+1, it hides the correct column
}
]
});

Thanks for your guidance.

Answers

  • pdxbugpdxbug Posts: 2Questions: 1Answers: 0

    On a side note, in order to merge right, I have to first subtract from index and then add 2? Very strange. I'm thinking something to do with declaring the variable somehow and the subtraction indicates to DataTables that it is a variable? I'm lost. Maybe a javascript thing where + is concatenation?

    'columnDefs': [
    {
    // The data parameter refers to the data for the cell (defined by the
    // data option, which defaults to the column being worked with, in
    // this case data: 0.
    'render': function ( data, type, row ) {
    var mergeinfo;
    if(data==''&&row[index]!=''){
    mergeinfo = row[index];
    } else if(data!=''&&row[index]==''){
    mergeinfo = data;
    } else if(data!=''&&row[index]!=''){
    mergeinfo = data+', '+row[index];
    } else if(data==''&&row[index]==''){
    mergeinfo = data;
    }
    return mergeinfo;
    },
    'targets': index-1+2 <--HERE, putting +1 and it gets ignored.
    },
    {
    'visible': false,
    'targets': index-1+1
    }
    ]

This discussion has been closed.