How to use colomn name in render function

How to use colomn name in render function

martin1223345martin1223345 Posts: 84Questions: 23Answers: 0

Hey guys,

I have a question that I think has a easy answer but I cant find how to do it on the forum..

The folowing code is used to send info to a ajax script when checkbox is checked or unchecked. What I now only sent the the data from kwartaal_id to the script. But I also need the colomn name to be send to the ajax script. So I need the colomn name the same as I do with the row.kwartaal_id. How do I do that? I imagine it would be like this..

"columns": [
                
                {data: 'kwartaal_klant',
                render: function ( data, type, row, meta ) {
                return ''+data+'';
                } } ,  
                    {data: 'kwartaal_notes',
                render: function ( data, type, row, meta ) {
                return ''+data+'';
                } } ,     
                {data: 'kwartaal_1'},
                {data: 'kwartaal_2'},
                {data: 'kwartaal_3'},
                {data: 'kwartaal_4'},
                {data: 'kwartaal_user',
                render: function ( data, type, row, meta ) {
                return ''+data+'';
                } } ,  
                 ], 

Before:

 {targets: [2,3,4,5], 
       render: function ( data, type, row ) {
         if ( type !== 'display' )
         
           return ""; //Empty cell content
         else {             //if column data is 1 then set attr to checked, use row id as input id (plus prefix)
           return '<label class="switch"><input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' value="' + row.kwartaal_id + '" class="active" /><div class="slider round"><span class="on">ON</span><span class="off">OFF</span></div></label>';
         }

         return data;
    },

After: (added the ''name'' atribute)

  {targets: [2,3,4,5], 
       render: function ( data, type, row ) {
         if ( type !== 'display' )
         
           return ""; //Empty cell content
         else {             //if column data is 1 then set attr to checked, use row id as input id (plus prefix)
           return '<label class="switch"><input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' value="' + row.kwartaal_id + '" 
           class="active" name="' + columnName + '" /><div class="slider round"><span class="on">ON</span><span class="off">OFF</span></div></label>';
         }

         return data;
    }, 

Answers

Sign In or Register to comment.