Add row and delete row

Add row and delete row

Wilmer30Wilmer30 Posts: 33Questions: 10Answers: 1

Hi,
With an a ajax I add a row:

            $.ajax({
              url: '<?php echo base_url();?>roles/saveRoles',
              data:datos,
              type: "POST",
              success: function(msg) {
                var row = table.row($(this).parents('tr')).data();
                console.log(msg);
                var dat = $.parseJSON(msg);
                  if(dat.msg == '1')
                    generate('success','El registro fue guardado satifactoriamente.');
                  else 
                    generate('error','Ocurrió un error al guardar el registro.');
                  $('#rol').val('');
                  $('#descripcion').val('');
                  $("#foo").modal('hide');
                        table.row.add( [
                            dat.data.id,
                            dat.data.rol,
                            dat.data.descripcion,
                            dat.data.status,
                            dat.data.accion
                        ] ).draw( false );
                }
            });

And I need to send the id by post:

        $('#datatable tbody').on( 'click','#delreg',function() {
          // var dat = table.row($(this).parents('tr')).data();
          var row = table.row($(this).parents('tr')).data();
          console.log(row[0]);
          $.ajax({
            url: '<?php echo base_url(); ?>roles/delRol',
            data: {id:row[0]},
            type: 'POST',
            success: function(msg){
              // table.row($(this).parents('tr')).remove().draw();
              // var row = table.row($(this).parents('tr'));
              // row.remove().draw();
            }
          });
        });

When the record is added with table.row.add().draw() does not send the post, but if it is loaded by default, it does

Answers

  • Wilmer30Wilmer30 Posts: 33Questions: 10Answers: 1

    The problem was resulted, it was a mistake that caused a misplaced link in the doom.

This discussion has been closed.