columnDefs in each loop

columnDefs in each loop

flowitflowit Posts: 2Questions: 1Answers: 1

Hi, I got problem. I need tu put indyvidual data.id in every 4 columns in each row.
i got succes function from ajax

[code]
success: function(data){

                $.each(data, function (key, data) {
                              $.each(data, function (index, data) {
                                if(data.status == '1') { var status = 'Aktywna'} else {var status = 'Nieaktywna'}
                                                                            var t = $('#pages').DataTable( {
                                                  "columnDefs": [ {
                                                    "targets": 4,
                                                    "createdCell": function (td, data) {

                                                        $(td).attr('this', +data.id);

                                                    }
                                                  } ]
                                                } );

                                 t.row.add( [
                                            "<td id='id'>"+data.id+"</td>",
                                             "<td>"+data.title+"</td>",
                                             "<td>"+status+"</td>",
                                             "<td id='meta_title' this="+data.id+" contenteditable='true'>"+data.meta_title+"</td>",
                                             "<td id='meta_description' this="+data.id+" contenteditable='true'>"+data.meta_description+"</td>",
                                             "<td><button type='button' id='delete' this="+data.id+" class='btn btn-danger'>USUŃ</button> <button type='button' id='edit' this="+data.id+" class='btn btn-info'>EDYTUJ</button></td>"

                                                ]).draw( false );

                                    })
                });

              },

[/code]

This need to be in each loop, becouse data.id in every row is diffrient, how to put columnDefs in each loop property ? of course this works, but there is a error and load each row with error, data loaded but need to press enter on each row, becouse datatable() is loaded every row. but if i put datatable() function out of each loop there is problem with columndDefs witch need to be inside this loop becouse there is thia data.id parametr. srry for english. I need this this="data.id" attr to use it later to edit content inline. i row.add function this what i write not working, becouse thats datatable function replace with shes <td> specifiaction witch is clear.

This question has an accepted answers - jump to answer

Answers

  • flowitflowit Posts: 2Questions: 1Answers: 1
    Answer ✓

    Ok got it, was wrong builded. Can`t use it lik this = blabla need to just find from id in DOM

This discussion has been closed.